0

我关注了https://cloud.google.com/speech/docs/getting-started并成功运行

curl -s -k -H "Content-Type: application/json" \
-H "Authorization: Bearer access_token" \
https://speech.googleapis.com/v1beta1/speech:syncrecognize \
-d @sync-request.json

得到预期的输出。但是,现在我试图做基本上相同的事情,但对于本地 flac 文件,所以我改为运行:

curl -s -k -H "Content-Type: audio/x-flac" -H "Authorization: Bearer [my access key]" 
https://speech.googleapis.com/v1beta1/speech:syncrecognize --data-binary @file.flac

我得到了回应

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unexpected     token.\nfLaC\u0000\u0000\u0000\"\u0004\n^",
    "status": "INVALID_ARGUMENT"
  }
}

google api 开发者控制台显示了进来的消息,但没有给我更多信息来帮助我。我也试过

wget --post-file file.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=[my api key]"

并且还收到 400 Bad Request 错误。

有没有人成功地实现了我的目标?我能找到的所有示例都是使用 api 上传文件或使用一些库,而不是简约的 curl 或 wget 请求。

4

1 回答 1

0

您应该尝试像这样引用数据二进制文件:

curl -s -k -H "Content-Type: audio/x-flac" -H "Authorization: Bearer [my access key]" 
https://speech.googleapis.com/v1beta1/speech:syncrecognize --data-binary @'file.flac'

我有同样的问题,这为我解决了。

于 2016-10-17T14:29:38.190 回答