Reputation: 498
I want to use Google Speech API's asynchronous transcription service. I've uploaded my audio file on Google buckets and I'm trying to use it with the following code (I've removed my key and my filename from the command, everything else is copied).
curl -H "Content-Type: application/json"
--data '{"audio":{"uri":"https://storage.cloud.google.com/<mybucketname>/<filename>"},
"config":{"encoding":"FLAC","sample_rate_hertz":"16000","language_code":"en_US"}}'
https://speech.googleapis.com/v1/speech:longrunningrecognize?key=<mykey>
I get a 400 INVALID_ARGUMENT error telling me "Request contains an invalid argument". What am I doing wrong in my curl request?
Upvotes: 6
Views: 2221
Reputation: 11164
I was using the Node JS Client and google storage to store the file.
// The audio file's encoding, sample rate in Hertz, and BCP-47 language code
const audio = {
uri: 'gs://sst_bbc/',
};
const config = {
enableWordTimeOffsets: true,
encoding: 'FLAC',
// sampleRateHertz: 16000,
languageCode: 'en-US',
};
const request = {
audio: audio,
config: config,
};
// Detects speech in the audio file
const [operation] = await client.longRunningRecognize(request);
const [response] = await operation.promise();
fs.writeFileSync('ted_talk.json', JSON.stringify(response), 'utf8');
I made a mistake by not referring to the exact object. The error in the console is very ambiguous. After I set the correct path it started to work properly.
const audio = {
uri: 'gs://sst_bbc/ted_talk.flac',
};
if the file location is correct then double check the encoding type.I
Upvotes: 0
Reputation: 69
Check the sample_rate_Hertz. You may find that is the format for SYNCHRONOUS requests.
ASYNCHRONOUS is sampleRateHertz.
I have just got it to work so revert if you need to while my memory is still fresh!
Upvotes: 0
Reputation: 498
Apparently the problem was in my URI. Google has a special way for referencing items in Google buckets, with "gs:" as the prefix.
curl -H "Content-Type: application/json"
--data '{"audio":{"uri":"gs://<mybucketname>/<filename>"},
"config":{"encoding":"FLAC","sample_rate_hertz":"16000","language_code":"en_US"}}'
https://speech.googleapis.com/v1/speech:longrunningrecognize?key=<mykey>
Note that I got a permission error that I could not overcome after I switched to this approach, but I don't think this is related to the way I'm making my curl request anymore.
Upvotes: 1