INVALID_ARGUMENT error by Google speech API

Viewed 1474

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?

4 Answers

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

Related