3

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..

Thomas David Kehoe
  • 10,040
  • 14
  • 61
  • 100
msethi00
  • 31
  • 1
  • 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 Apr 17 '17 at 18:12
  • 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 Apr 17 '17 at 20:45

3 Answers3

1

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)

Community
  • 1
  • 1
A. STEFANI
  • 6,707
  • 1
  • 23
  • 48
  • 4
    This was Google's .FLAC file provided in their own example; hopefully they provide something that works. – NealWalters Apr 27 '17 at 17:20
  • 1
    Sorry for my bad answer, may you please add/update your functional code (as example) – A. STEFANI Apr 27 '17 at 18:20
  • We were both running demo exactly as per the sample Google website, see URL posted by original question. The post I made in Google Group indicate that CURL as interpreting the contents of the file as CURL commands, and thus not really the JSON for the web service call. – NealWalters May 02 '17 at 13:55
0

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

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.

NealWalters
  • 17,197
  • 42
  • 141
  • 251
  • Trying to apply the solution without a space between the -d and @ without success: it seems not to make any difference. – George May 01 '17 at 21:01
  • I was using the CURL from CYGWIN: https://www.cygwin.com/. I couldn't find any doc on why the space mattered, but I was getting exact same error as you and the change allowed it to work. Maybe there are variation in different CURL implementations? – NealWalters May 02 '17 at 13:54
  • There might also be a way to pass the JSON on the CURL command line, I didn't try that. – NealWalters May 02 '17 at 13:57
0

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>"
  }
}
The Cloud Guy
  • 963
  • 1
  • 8
  • 20