0

I followed https://cloud.google.com/speech/docs/getting-started and successfully ran

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

to get the expected output. However, now I am trying to do essentially the same thing but for a local flac file so I'm instead running:

curl -s -k -H "Content-Type: audio/x-flac" -H "Authorization: Bearer [my access key]" 
https://speech.googleapis.com/v1beta1/speech:syncrecognize --data-binary @file.flac

and I'm getting a response of

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unexpected     token.\nfLaC\u0000\u0000\u0000\"\u0004\n^",
    "status": "INVALID_ARGUMENT"
  }
}

The google api developer console shows the message coming in but give me no further information to help me. I've also tried

wget --post-file file.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=[my api key]"

and am also getting a 400 Bad Request error.

Has anyone successfully achieved what I'm shooting for? All of the examples I can find are for either using the api for an uploaded file or using some libraries, as opposed to a minimalistic curl or wget request.

raph
  • 350
  • 2
  • 10

1 Answers1

0

You should try quoting the data-binary file like this:

curl -s -k -H "Content-Type: audio/x-flac" -H "Authorization: Bearer [my access key]" 
https://speech.googleapis.com/v1beta1/speech:syncrecognize --data-binary @'file.flac'

I had the same issue and this solved it for me.

Serge Hendrickx
  • 1,416
  • 9
  • 15
  • I'll give it a shot later and let you know how it works. Thanks – raph Oct 18 '16 at 13:48
  • So I tried adding the single quotes around the filename and still got the same error. Any other suggestions? – raph Nov 06 '16 at 16:04