【发布时间】:2021-04-01 00:11:57
【问题描述】:
我在节点 js 中使用 Google 的 Speech-to-Text 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 秒识别良好,然后什么都没有。
任何帮助将不胜感激!
【问题讨论】:
-
如何打印结果?您是否像在您遵循的示例代码中一样打印结果?
标签: google-cloud-platform speech-recognition speech-to-text google-speech-api