Cloud Speech API error: RecognitionAudio not set

7k Views Asked by At

While trying to follow the [quick start] (https://cloud.google.com/speech/docs/getting-started) for cloud speed API, after execute the "curl" command in command prompt, error occurred depicted as below:

{
  "error": {
  "code": 400,
  "message": "RecognitionAudio not set.",
  "status": "INVALID_ARGUMENT"
  }
}

Why the RecognitionAudio is not set in the API itself? The sync-request.json used is same as the one in the quick start:

{
  "config": {
      "encoding":"FLAC",
      "sampleRateHertz": 16000,
      "languageCode": "en-US",
      "enableWordTimeOffsets": false
  },
  "audio": {
      "uri":"gs://cloud-samples-tests/speech/brooklyn.flac"
  }
}
4

There are 4 best solutions below

0
On

I'm not sure exactly what you're doing wrong but I was able to use the request as-is from the documentation without issue.

Did you get an access token for a Google Cloud project that had the speech API enabled? The following command generates the access token that can be used as a Bearer:

gcloud auth application-default print-access-token

It was helpful for me to use put the following into a script file (req.sh)

curl -s -H "Content-Type: application/json" \
    -H "Authorization: Bearer <output>" \
    https://speech.googleapis.com/v1/speech:recognize \
    -d @sync-request.json

I then just used the output from print-access-token with the script.

1
On

I had the same problem and it worked for me when I omitted the @sync- from the curl command. This command worked for me:

curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer " \
https://speech.googleapis.com/v1/speech:recognize \
-d @request.json

Not sure what the exact function is of @sync ?

1
On

I had exactly the same problem and I solved it adding quotes in the -d value, like this:

curl -s -H "Content-Type: application/json" \
    -H "Authorization: Bearer <your-access-token>" \
    https://speech.googleapis.com/v1/speech:recognize \
    -d "@sync-request.json"
0
On

I was getting this error because I was not running the command in the cli in the same directory as my sync-request.json file.

Once I changed directories, I used the command from the documentation with my access token, and it worked fine.