Search code examples
pythongoogle-cloud-platformspeech-to-textgoogle-speech-api

How to retrieve google speech api asynchronous request response ?


I'm trying to make the asynchronous google-speech-api request work. As advised I use play command:

play audio2min.flac

enter image description here

Using the code from here : https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/speech/api-client. I then adapt the request with corresponding encoding.

I then get the error :

"Audio 'content' cannot be longer than 1 min.
For long audio, use the 'uri' parameter to specify a file."

I then put my file in google storage and adapt my request with "uri": "gs://path/to/my/audio2min.flac"

But then I get the error :

For audio inputs longer than 1 min, please use LINEAR16 encoding.

The problem is : When I change the encoding for LINEAR16 instead of FLAC, I get a void answer.

To make sure encoding was really the problem, I tried with a 30sec sample from my file with the synchronous requests. It worked with encoding FLAC but not with encoding LINEAR16.

Can anybody explain me how what should I do from here ?


Solution

  • I finally managed to make it work by changing the encoding of my file.

    1. Download audacity : http://www.audacityteam.org/

    2. Open your file

    3. In File -> Export Audio -> Choose :

    other uncompressed files

    Header : RAW

    Encoding : 16-bit PCM

    enter image description here

    Now it should work