Search code examples
node.jstimeoutgoogle-speech-apigoogle-cloud-speech

Google speech API timeout time


I'm trying to use the Speech API client APIs in order to convert an audio file to text.

So far I have succeeded in converting a short audio clip, but now with a longer file (10 minutes) I get this error:

Retry total timeout exceeded before anyresponse was received

I've read in the docs that with async calls the maximum amount of minutes is 60 per call, and I have uploaded the file to Google Cloud Storage, as it's needed for files longer than 1 minute.

So I really don't see why I'm getting that error, any help?


Solution

  • By default there is a system timeout of 10 minutes. This is a known issue for other Google Cloud services, but the fix suggested there did not work for me, I assume it's something else to be set when you run your code and start your connection.

    Anyways, there is a workaround! You get the long running operation name, and then you stop your program. The operation will continue on the google server, and later you will fetch the result!

    As written in the docs

    Asynchronous Speech Recognition starts a long running audio processing operation.

    I will refer to the node.js sample here, similar concepts will apply for others. So, when you get your response (do not use the promise version) pass it a callback, like explained here, and instead of

    operation
        .on('error', function(err) {})
        .on('complete', function(transcript) {
          // transcript = "how old is the Brooklyn Bridge"
        });
    

    just do something like

    console.log(operation)
    

    take note of the operation name, and later on use the operation method

    You can test these on the google oauth playground