I am trying to use Google.Cloud.Speech.V1
(client libraries for Google Cloud Speech API), and I am using this slightly modified version of Google's sample code:
public async Task<string> TranscribeSpeech(string filenameAndPath, int WAVSampleRate = 8000)
{
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Utils.GetHomeFolder() + @"\Google Speech API Key.json"); //for authentication
var language = WebConfigurationManager.AppSettings["GoogleSpeechFromLocale"];
var speech = SpeechClient.Create();
var response = await speech.RecognizeAsync(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
SampleRateHertz = WAVSampleRate,
LanguageCode = language,
}, RecognitionAudio.FromFile(filenameAndPath));
return response.Results.First().Alternatives.First().Transcript;
}
The .Recognize()
or .RecognizeAsync()
methods never return anything and throw an exception after 10 minutes saying Status(StatusCode=DeadlineExceeded,Detail="Deadline Exceeded")!
.
In other words, when I debug line by line in Visual Studio, the code never continues after await speech.RecognizeAsync()
and just keeps pending until it throws an exception 10 minutes later.
Is there an issue with my code or with the API settings?
My input file is usually only 2-3 seconds long and has the following format (output from ffmpeg
):
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
My application's code is hosted on Azure. The Google Cloud Platform Console shows that there were no API calls - probably meaning that my requests somehow don't reach the Google server.
The same application also makes calls to Bing Speech API and they are successful.
If I run the call from https://developers.google.com/apis-explorer/?hl=en_US#p/speech/v1beta1/speech.speech.syncrecognize with the same WAV file, it succeeds.
speech.RecognizeAsync(rc, RecognitionAudio.FromStorageUri(url));
, with your url being something likegs://my_bucket/test.raw
. that should rule out problems caused by file transfers. – Smarm