我已经管理了“概述教程”:https://cloud.google.com/speech/docs/getting-started,然后我尝试使用自己的音频文件。我上传了一个采样率为16000 of的.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"
}
}发布于 2017-02-13 21:58:29
根据这的答案,所有编码只支持一个通道(单通道)音频。
我使用以下命令创建FLAC文件:
ffmpeg -i test.mp3 test.flac请求中的采样率与FLAC报头不匹配。
但是添加-ac 1 (将音频通道的数量设置为1)解决了这个问题。
ffmpeg -i test.mp3 -ac 1 test.flac这是我的完整Node.js代码
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。云语音文档
发布于 2016-09-21 16:44:00
我的错,作为文档"https://cloud.google.com/speech/docs/basics",.flac文件必须是一个16位PCM。
总结:
编码: FLAC
频道:1@16位
采样频率:16000
/!\注意不要导出立体声文件(2个通道),该文件会引发另一个错误(仅接受一个通道) Google语音API内部服务器错误-83104
https://stackoverflow.com/questions/39620198
复制相似问题