我通常使用格式正确的 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/