Google Speech-to-Text: Invalid recognition 'config': bad sample rate hertz

Viewed 1855

I am trying to convert speech to text using the REST full service. I am using .wav file (PCM 16 bit Mono 16000 HZ)

URL: https://speech.googleapis.com/v1p1beta1/speech:recognize

JSON request:

{
    "config": {
        "enableAutomaticPunctuation": "true",
        "encoding": "LINEAR16",
        "languageCode": "en-US",
        "model": "default"
    },
    "audio": {
        "content": "QzpcU3BlZWNoVG9UZXh0XGVuZ2xpc2hcUENNXEVORy1DUk0tRE9XTlRJTUUud2F2"
    }
}

Error:

"error": {
    "code": 400,
    "message": "Invalid recognition 'config': bad sample rate hertz.",
    "status": "INVALID_ARGUMENT"
}

Could you please help to resolve this error?

1 Answers

The API request needs to specify a sampleRateHertz, which is the sample rate of the audio you sent, in Herz.

In your case, that's 16000, so your request should include:

"config": {
    ...,
    "sampleRateHertz": 16000
}
Related