user6269864
user6269864

Reputation:

Call to Google Cloud Speech API doesn't return anything, fails after 10 minutes

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.

Upvotes: 10

Views: 2283

Answers (2)

user6269864
user6269864

Reputation:

Resolved the issue by commenting out the SampleRateHertz:

        var response = await speech.RecognizeAsync(new RecognitionConfig()
        {
            Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
            //SampleRateHertz = WAVSampleRate,
            LanguageCode = language,
        }, RecognitionAudio.FromFile(filenameAndPath));

The error message was:

sample_rate_hertz (8000) in RecognitionConfig must either be omitted or match the value in the WAV header (48000)

Upvotes: 0

King Reload
King Reload

Reputation: 2952

I take you followed the installation guide on: https://cloud.google.com/speech/docs/reference/libraries if you did, everything should work fine.

However there is a maximum of how much you can use it for.

1 the content limit:

1-1 Synchronous Requests around 1 minute.

1-2 Asynchronous Requests around 80 minutes.

1-3 Streaming Requests, also around the 1 minute.

2 Speech context limit:

2-1 Phrases per request goes up to value of 500.

2-2 Total characters per request goes up to 10k characters.

2-3 Characters per phrase goes up to 100.

Audio longer than ~1 minute must use the uri field to reference an audio file in Google Cloud Storage.

For StreamingRecognize requests, audio must be sent at a rate that approximates real time.

Attempting to process content in excess of these content limits will produce an error.

If you want to know more limitations of the Google Speech API I recommend you to look into this: https://cloud.google.com/speech/limits as I also got the same error for exceeding the limit in another google API.

Upvotes: 4

Related Questions