0
votes
{
  "config": {
      "encoding":"FLAC",  
      "sample_rate": 16000,  
      "language_code": "en-US"
  },
  "audio": {
      "uri":"gs://speechtotextapi/audio_file.flac"
  }
}

curl -s -X POST -H "Content-Type: application/json" --data-binary @request.json \ "https://speech.googleapis.com/v1/speech:recognize?key=${API_KEY}"

Initially I converted the mp4 file to FLAC format and then uploaded it to the bucket. This is the api response.

{ "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \"sample_rate\" at 'config': Cannot find field.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "field": "config", "description": "Invalid JSON payload received. Unknown name \"sample_rate\" at 'config': Cannot find field." } ]

2
Issue resolved.Rajul

2 Answers

0
votes

You need to construct the properly formatted input as an array and then json encode it. For example, to send a file, base64encode it as "content" and submit to the API as shown:

$upload = base64_encode(file_get_contents(NAME_OF_YOUR_AUDIO_FILE));

"audio" => array( "Content" => $upload, )

0
votes

change attribute sample_rate in sampleRateHertz