请求协助解决Google Speech-to-Text采样率配置无效的400错误
Looks like that error is pointing to a simple but critical missing piece in your request. Let's break down what's going wrong and fix it right away:
1. The Root Issue
Google's Speech-to-Text API requires you to explicitly define your audio's sample rate in the config object—even if you're using a standard rate like 16000 Hz. Your current request doesn't include the sampleRateHertz field, so the API can't properly parse your 16kHz WAV file.
Also, there's a tiny syntax issue with your enableAutomaticPunctuation value: you passed it as a string "true" instead of a JSON boolean true (no quotes). While this isn't causing your current error, it could lead to unexpected behavior later, so we'll fix that too.
2. Corrected Request JSON
Here's the revised version of your request with both fixes applied:
{ "config": { "enableAutomaticPunctuation": true, "encoding": "LINEAR16", "languageCode": "en-US", "model": "default", "sampleRateHertz": 16000 }, "audio": { "content": "QzpcU3BlZWNoVG9UZXh0XGVuZ2xpc2hcUENNXEVORy1DUk0tRE9XTlRJTUUud2F2" } }
3. Quick Reminders
- Double-check that
sampleRateHertzexactly matches your audio's actual sample rate (16000 Hz in your case). Mismatched values will trigger the same error. - JSON boolean values (
true/false) should never be wrapped in quotes—use them as raw boolean types. - Your
encoding: "LINEAR16"is perfect for your PCM 16-bit mono audio, so no changes needed there.
Give this updated request a shot, and it should resolve that 400 error you're hitting.
内容的提问来源于stack exchange,提问作者Tarun

