Dam*_*ito 4 flac google-cloud-speech
我已经管理了"概述教程":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"
}
}
Run Code Online (Sandbox Code Playgroud)
该文件已被很好地识别,但请求返回"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"
}
}
Run Code Online (Sandbox Code Playgroud)
根据这个答案,所有编码仅支持1声道(单声道)音频
我用这个命令创建了FLAC文件:
ffmpeg -i test.mp3 test.flac
Run Code Online (Sandbox Code Playgroud)
请求中的采样率与FLAC标头不匹配
但添加-ac 1(设置音频通道数为1)解决了这个问题.
ffmpeg -i test.mp3 -ac 1 test.flac
Run Code Online (Sandbox Code Playgroud)
这是我的完整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);
});
Run Code Online (Sandbox Code Playgroud)
采样率可以是16000或44100或其他有效值,编码可以是FLAC或LINEAR16.云语音文档
| 归档时间: |
|
| 查看次数: |
5424 次 |
| 最近记录: |