我在node js中使用了Google的语音转文本API。它返回对前几个单词的识别,但随后会忽略音频文件的其余部分。对于任何上传的文件,截止点大约是5-7秒。
我试过synchronous speech recognition for shorter audio files。(使用如下所示的MP3文件的示例)
filename = './TEST/test.mp3';
const client = new speech.SpeechClient();
//configure the request:
const config = {
enableWordTimeOffsets: true,
sampleRateHertz: 44100,
encoding: 'MP3',
languageCode: 'en-US',
};
const audio = {
content: fs.readFileSync(filename).toString('base64'),
};
const request = {
config: config,
audio: audio,
};
// Detects speech in the audio file
const [response] = await client.recognize(request);我也尝试过asynchronous recognition for longer audio files (使用WAV文件的例子如下所示)
filename = './TEST/test.wav';
const client = new speech.SpeechClient();
//configure the request:
const config = {
enableWordTimeOffsets: true,
languageCode: 'en-US',
};
const audio = {
content: fs.readFileSync(filename).toString('base64'),
};
const request = {
config: config,
audio: audio,
};
//Do a longRunningRecognize request
const [operation] = await client.longRunningRecognize(request);
const [response] = await operation.promise();我已经用WAV文件和MP3尝试了每一种实现。结果总是完全相同的:在前5秒内识别良好,然后什么都没有。
任何帮助都将不胜感激!
发布于 2021-04-01 00:11:58
@Ricco D是绝对正确的,我错误地打印了结果...
当你试图转录更长的文件时,Google speech to Text会根据它在语音中检测到停顿的时间来打断你的转录。
您的response.results[]数组将有多个条目,您需要遍历这些条目才能打印完整的文本。
有关更多细节,请参阅文档:https://cloud.google.com/speech-to-text/docs/basics#responses
https://stackoverflow.com/questions/66855927
复制相似问题