google-speech-api - google cloud speech to text rest api return empty response
问题描述
I tried to use google cloud speech to text API, by using the sample page (https://cloud.google.com/speech-to-text/). It works fine after I upload my audio file (.m4a)
Then I try to call these services using rest API and the same audio file, it does not work.
I get 200 with an empty response.
I call rest API with this info
POST https://speech.googleapis.com/v1p1beta1/speech:recognize?key=SOME_KEY
body:
{
"audio": {
"content": "base64 audio content"
},
"config": {
"sampleRateHertz": 16000,
"encoding": "LINEAR16",
"languageCode": "en-US"
}
}
but on https://cloud.google.com/speech-to-text/, the body is different a little bit like this
{
"audio": {
"content": "/* Your audio */"
},
"config": {
"enableAutomaticPunctuation": true,
"encoding": "LINEAR16",
"languageCode": "en-US",
"model": "default"
}
}
I don't know why it does not work when calling rest API.
Please help
Updated =>
I read audio file by this code (example from google doc)
const file = fs.readFileSync('FILE_LOCATION')
const audioBytes = file.toString('base64')
解决方案
阅读文档,我找不到 Google Text To Speech 支持的“.m4a”(Apple Lossless)文件的引用。事实上,恰恰相反。
我的建议是,至少尝试将您的文件转换为 WAV 格式文件并提供该文件。如果可行,请查看是否无法以这种格式获取原始音频。
看:
推荐阅读
- laravel - 在 laravel 5.6 中表单输入旧值
- python - python在数据框中移动数据
- python - Python 3.6 导入 cv2 库
- python - Python 从字符串中获取参数
- python - 如何在组合之前移动图像(相对于另一个图像)?
- spring - 使用 Spring Boot 2 的 Docker 堆栈“配置”
- node.js - Angular SSL 证书和密钥——Ng 服务根目录
- java - 需要一个 android 按钮来执行一个故意空白的 EditText 框
- omnet++ - 在 ubuntu 上修改 Castlia 3.3 + omnetpp 5.3 - 权限被拒绝
- d3.js - 减少词云 zingcharts 中的空白?