我已经管理了“概述教程”:https://cloud.google.com/speech/docs/getting-started https://cloud.google.com/speech/docs/getting-started然后我尝试使用我自己的音频文件。我上传了一个采样率为 16000Hz 的 .flac 文件。
我只改变了sync-request.json
下面的文件包含我自己托管在谷歌云存储上的音频文件(gs://my-bucket/test4.flac
)
{
"config": {
"encoding":"flac",
"sample_rate": 16000
},
"audio": {
"uri":"gs://my-bucket/test4.flac"
}
}
该文件已被很好地识别,但请求返回“INVALID_ARGUMENT”错误
{
"error": {
"code": 400,
"message": "Unable to recognize speech, code=-73541, possible error in recognition config. Please correct the config and retry the request.",
"status": "INVALID_ARGUMENT"
}
}
As per this https://cloud.google.com/speech/docs/basics答案,所有编码仅支持 1 个通道(单声道) audio
我使用以下命令创建 FLAC 文件:
ffmpeg -i test.mp3 test.flac
请求中的采样率与 FLAC 标头不匹配
但添加-ac 1
(将音频通道数设置为 1)修复了此问题。
ffmpeg -i test.mp3 -ac 1 test.flac
这是我的完整版Node.js
code
const Speech = require('@google-cloud/speech');
const projectId = 'EnterProjectIdGeneratedByGoogle';
const speechClient = Speech({
projectId: projectId
});
// The name of the audio file to transcribe
var fileName = '/home/user/Documents/test/test.flac';
// The audio file's encoding and sample rate
const options = {
encoding: 'FLAC',
sampleRate: 44100
};
// Detects speech in the audio file
speechClient.recognize(fileName, options)
.then((results) => {
const transcription = results[0];
console.log(`Transcription: ${transcription}`);
}, function(err) {
console.log(err);
});
采样率可以是 16000 或 44100 或其他有效值,编码可以是 FLAC 或 LINEAR16。云语音文档 https://cloud.google.com/speech/docs/basics
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)