0
{
  "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." } ]

Rajul
  • 71
  • 9

2 Answers2

0

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, )

user223321
  • 155
  • 1
  • 15
  • This is the response im getting after modifying the request curl -s -X POST -H "Content-Type: application/json" -d @request.json \ "https://speech.googleapis.com/v1/speech:longrunningrecognize?key=${API_KEY}" { "name": "283477145540444562" }. I'm not seeing any text/string as output. Any idea as to what is happening? – Rajul Sep 05 '17 at 19:25
  • Just found out that I will get the actual text using the GET request https://speech.googleapis.com/v1/operations/YOUR_OPERATION_NAME?key=YOUR_API_KEY – Rajul Sep 05 '17 at 20:22
0

change attribute sample_rate in sampleRateHertz try this:

{
  "config": {
      "encoding":"FLAC",  
      "sampleRateHertz": 16000,  
      "language_code": "en-US"
  },
  "audio": {
      "uri":"gs://speechtotextapi/audio_file.flac"
  }
}
dakota
  • 1
  • 1
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 05 '21 at 04:59