Google云语音识别“INVALID_ARGUMENT”
问题描述:
我管理了“概览教程”:https://cloud.google.com/speech/docs/getting-started 然后我尝试使用我自己的音频文件。我上传了一个采样率为16000Hz的.flac文件。Google云语音识别“INVALID_ARGUMENT”
我只是改变了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"
}
}
答
作为每this答案,所有编码支持仅1个通道(单声道)音频
我创建用这个命令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。 Cloud Speech Docs
答
我的不好,作为文档“https://cloud.google.com/speech/docs/basics”,.flac文件必须是16位PCM
Sumup:
编码:FLAC
通道:1 @ 16位
采样率:16000,
/\注意不能导出立体声文件(2个通道)文件,它抛出一个其它错误(仅一个信道被接受)Google speech API internal server error -83104