according to https://cloud.google.com/speech/quotas, asyncronous request lasts 180 minutes.
But when I use this code:
public async Task<object> StreamingMicRecognizeAsync(int seconds)
{
streamingCall = SpeechClient.Create().StreamingRecognize();
await streamingCall.WriteAsync(
new StreamingRecognizeRequest()
{
StreamingConfig = new StreamingRecognitionConfig()
{
Config = new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
SampleRateHertz = 16000,
LanguageCode = "en-US"
},
InterimResults = true,
SingleUtterance = false
}
}
);
Task prinResp = Task.Run(async () =>
{
while (await streamingCall.ResponseStream.MoveNext(default(CancellationToken)))
{
foreach (var result in streamingCall.ResponseStream.Current.Results)
{
MessageBox.Show(result.Alternatives[0].Transcript.ToString());
}
}
});
// Read from the microphone and stream to API.
object writeLock = new object();
bool writeMore = true;
waveIn = new NAudio.Wave.WaveInEvent();
waveIn.DeviceNumber = 0;
waveIn.WaveFormat = new NAudio.Wave.WaveFormat(16000, 1);
waveIn.DataAvailable +=
(object sender, NAudio.Wave.WaveInEventArgs args) =>
{
lock (writeLock)
{
if (!writeMore || !isActive) return;
try
{
streamingCall.WriteAsync(
new StreamingRecognizeRequest()
{
AudioContent = Google.Protobuf.ByteString.CopyFrom(args.Buffer, 0, args.BytesRecorded)
}).Wait();
}
catch (Exception e) { my.message(e.Message); }
}
};
waveIn.StartRecording();
await Task.Delay(TimeSpan.FromSeconds(180*60));
waveIn.StopRecording();
lock (writeLock) writeMore = false;
await streamingCall.WriteCompleteAsync();
await prinResp;
return 0;
}
after 65 seconds streamingCall.WriteAsync
shows "Exceeded maximum allowed stream duration of 65 seconds." error.
How do i Get 180 minutes? ( i.e. on translate.google.com you can use "speak" feature more than minute, how can achieve it)?
As @CamiloTerevinto mentioned, you will need to provide a Cloud Storage URI for your Speech API's Asynchronous request to last more than 1 minute. Translate.google.com is a Google tool and those not have the same limitations as a public API. I also believe the translate tool stream the audio, uploads it to a temporary cloud storage, uses speech API to convert to text so it can be translated.
You can upload the stream to Google Cloud Storage using Google.Cloud.Storage.V1 API. The return URI can then be used with the Speech API Asynchronous request and should process up to 180 min of audio.
Google has a couple of small examples on how to use the Speech API with different scenarios, including with the Google Storage URI. I would suggest looking into it.
Hope it helps