0

I don't find how to send a local file using the Google STT in curl command line. As followed in their tuto, here my request.json :

{
"config": {
      "encoding":"FLAC",
      "sample_rate": 16000,
      "language_code": "fr-FR"
  },
  "audio": {
      "uri":"audio-file.flac"
  }
}

my command line is:

curl -s -X POST -H "Content-Type: application/json" --data-binary @request.json "https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=MY_API_KEY"

But I receive the error result:

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

How can I write the request.json to send a local audio file ?? Thanks for help :)

Gab
  • 23
  • 7

2 Answers2

1

You need to use the base64 in the content section of the request.json file. It should look something like this except with a lot more base64 data:

{
  'config': {
    "encoding":"FLAC",
    "sample_rate": 16000,
    "language_code": "fr-FR"
  },
  'audio': {
    'content':'UklGRuRDFQBXQVZFZm10IBAAAAABAAEAQB8AAIA+AAACABAAZGF0YcBDFQAIAAgACAAIAAgA
CAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgA
CAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgA
CAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAD4/wgACAD4//j/+P8IAPj/+P8IAAgA
+P8IAAgACAAIAAgA+
'
  }
}
Beto
  • 28
  • 3
0

Google doesn't provide an option to specify local file path in json object while using curl command.We are require to convert audio file into base64 and pass the output into json object

 base64 source_audio_file -w 0 > dest_base64_audio_file_content

Alternatively one of the best approach to pass localfile is to use gcloud ml command.

gcloud ml speech recognize 'Clip48_Mike.wav' --language-code='en-US'  

Example: enter image description here

NOTE: Following command to activate gcloud account if not already done.

gcloud auth activate-service-account --key-file /tmp/account-name.json
Shahid Hussain
  • 1,599
  • 1
  • 20
  • 24