2
votes

I am trying to follow the example on google speech api found here

https://cloud.google.com/speech/docs/getting-started

1) I created the follow json request file

{
    'config': {
          'encoding':'FLAC',
          'sampleRate': 16000,
          'languageCode': 'en-US'
    },
    'audio': {
         'uri':'gs://cloud-samples-tests/speech/brooklyn.flac'
    }
}

2) Authenticate to my service account

gcloud auth activate-service-account --key-file=service-account-key-file

3) Obtain my authorization token successfully

gcloud auth print-access-token
access_token

4) Then use the following curl command

curl -s -k -H "Content-Type: application/json" \
    -H "Authorization: Bearer access_token" \
    https://speech.googleapis.com/v1beta1/speech:syncrecognize \
    -d @sync-request.json

But I keep getting the following response

{
  "error": {
    "code": 400,
    "message": "Invalid recognition 'config': bad encoding..",
    "status": "INVALID_ARGUMENT"
  }
}

Do I need access permissions for the uri gs://cloud-samples-tests/speech/brooklyn.flac? Is that what the problem is?

Thanks in advance..

3
I just got exact same issue trying my first test. I was using the cygwin64 version of CURL on Windows 10. Sounds to me like it cannot interpret the json file. I tried saving it as Unicode, but that's gave what I thought was a worse error.NealWalters
You might also try taking off the -s for "Silent". If like me, you will see more errors that might be hints. I'm still trying to figure it out too.NealWalters

3 Answers

1
votes

In my opinion, it is a file format issue.

You have to send WAV file instead of FLAC ...

[ FLAC and MP3 format are not supported <=> need a file conversion (representing cost) on the server side ]

Convert your audio file to WAV (using ffmpeg or avconv), then retry.

You may also take a look here (to see a working example)

0
votes

For me, the solution was to remove the space between "-d @", so change "-d @sync-request.json" to "[email protected]".

I got help here: https://groups.google.com/forum/#!topic/cloud-speech-discuss/bL_N5aJDG5A. Apparently the file was being read and processed, but the parms were going to the "curl.exe" instead of being passed to the URL.

0
votes

I understand this is quite late for an answer. However, it might help others so putting in your error.

The config that you are passing is actually incorrect. The attributes should be like:

{
  "config": {
  "encoding": "LINEAR16",
  "sampleRateHertz": 16000,
  "languageCode": "en-US",
  "maxAlternatives": 1,
  "profanityFilter": true,
  "enableWordTimeOffsets": false
},
  "uri": {
    "content":"<your uri>"
  }
}