Google 语音 API 的 INVALID_ARGUMENT 错误

Roo*_*han 5 json curl google-speech-api

我想使用 Google Speech API 的异步转录服务。我已将我的音频文件上传到 Google 存储桶,并尝试将其与以下代码一起使用(我已从命令中删除了我的密钥和文件名,其他所有内容都已复制)。

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>
Run Code Online (Sandbox Code Playgroud)

我收到 400 INVALID_ARGUMENT 错误,告诉我“请求包含无效参数”。我在 curl 请求中做错了什么?

Roo*_*han 1

显然问题出在我的 URI 中。Google 有一种特殊的方式来引用 Google 存储桶中的项目,以“gs:”作为前缀。

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>
Run Code Online (Sandbox Code Playgroud)

请注意,在切换到这种方法后,我遇到了无法克服的权限错误,但我认为这与我发出卷曲请求的方式不再相关。