I tried to use google cloud speech to text API, by using the sample page (https://cloud.google.com/speech-to-text/). It works fine after I upload my audio file (.m4a)
Then I try to call these services using rest API and the same audio file, it does not work.
I get 200 with an empty response.
I call rest API with this info
POST https://speech.googleapis.com/v1p1beta1/speech:recognize?key=SOME_KEY
body:
{
"audio": {
"content": "base64 audio content"
},
"config": {
"sampleRateHertz": 16000,
"encoding": "LINEAR16",
"languageCode": "en-US"
}
}
but on https://cloud.google.com/speech-to-text/, the body is different a little bit like this
{
"audio": {
"content": "/* Your audio */"
},
"config": {
"enableAutomaticPunctuation": true,
"encoding": "LINEAR16",
"languageCode": "en-US",
"model": "default"
}
}
I don't know why it does not work when calling rest API.
Please help
Updated =>
I read audio file by this code (example from google doc)
const file = fs.readFileSync('FILE_LOCATION')
const audioBytes = file.toString('base64')
Reading the docs, I could find no reference to ".m4a" (Apple Lossless) files being supported by Google Text To Speech. In fact, quite the reverse.
What I'd suggest is, at a minimum, try converting your file to a WAV format file and supplying that. If that works, see if you can't get your raw audio in such a format.
See: