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

2

10

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.

Lambertson answered 21/4, 2017 at 5:46 Comment(2)
The fact that your cloud platform console shows no API calls means nothing. I have been using the speech API for months, and nothing shows up. Have you tried running your code from a simple console app, just to rule out Azure as a problem source? The code works fine for me.Smarm
Another thing to try is to upload the file to a bucket in google cloud storage and then use speech.RecognizeAsync(rc, RecognitionAudio.FromStorageUri(url));, with your url being something like gs://my_bucket/test.raw. that should rule out problems caused by file transfers.Smarm
D
4

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.

Disagreement answered 29/4, 2017 at 22:17 Comment(2)
Our team was hit by this last year.. It turned out that we exceeded Max requests per day limit.. We were running an automation script to process tons of audio samples and characterize different platforms performance across various parameters. We had a corporate relationship with Google and to continue our analysis we got the limitation waived off for our development user accountInfernal
My audio is just 2-3 seconds long, so I won't mark this answer accepted for now. Thanks for your research.Lambertson
L
0

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)

Lambertson answered 18/5, 2017 at 2:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.