curl - google speech api 空结果 JSON

标签 curl google-api speech-to-text google-speech-api

我通常使用格式正确的 JSON 请求和 mp3 文件进行 API 调用,我希望结果 JSON 数据包含“结果”对象和“替代”对象以及“成绩单”和“置信度”值。

相反,我得到的结果是“{}”(一个空的 JSON 对象)。

使用的操作系统是ubuntu15.04。

已创建具有以下文本的 JSON 请求文件,并将其保存为 sync-request.json 纯文本文件:

{
  "config": {
    "encoding": "LINEAR16",
    "sampleRate": 16000,
"languageCode": "en-US"
  },
  "audio": {
    "uri": "gs://audiobucketceino/Learn English - Lesson 41- Hi How are you - Pronunciation-[AudioTrimmer.com].mp3"
  }
}

用来做演讲的curl:syncrecognize请求是:

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

测试文件附在:

https://drive.google.com/file/d/0B7cqXnHXm78bLWdyYWhpVEdkT0U/view?usp=sharing

最佳答案

google speech API 不直接支持 mp3 文件。它只支持 the five listed in the documentation .最简单的方法是使用 sox 或类似工具 (sudo apt-get install sox) 将 mp3 文件转换为 wav 文件:

sox lesson41.mp3 lesson41.wav

wav 文件应该与您提供的 LINEAR16 编码兼容。您需要确保采样率为 16k,样本为 16 位。为了安全起见,试试这个:

sox lesson41.mp3 -r 16000 -c 1 -b 16 lesson41.wav

如果您在获取 sox 时遇到任何问题,可以使用 lots of other tools that should be able to do the conversion too .

关于curl - google speech api 空结果 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42156740/

相关文章:

javascript - 使用 Google API 检索联系人姓名

c# - 如何使用 SAPI 进行语音转文本?

python - 使用Python中的Azure语音服务读取音频文件并转换为文本,但只有第一句话转换为语音

c++ - 使用 opencv 和 cURL 从 url 加载图像

google-api - 谷歌群组设置 API 的域范围委派身份验证?

php - PayPal IPN 无效进程

java - 如何绕过 Google Sheets V4 API 不返回空单元格

python - 谷歌云语音到 Python 中的文本 : Save translation and time to JSON

javascript - 这个curl 请求的node.js 等价物是什么?

用于组装的 python curl