google-cloud-platform - Google Speech to Text(语音识别)仅识别音频的前几秒
问题描述
我在节点 js 中使用 Google 的 Speech-to-Text API。它返回对前几个单词的识别,但随后忽略音频文件的其余部分。任何上传文件的截止点约为 5-7 秒。
我尝试过对较短的音频文件进行同步语音识别。(使用 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);
而且我还尝试过对较长的音频文件进行异步识别 (使用如下所示的 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 秒识别良好,然后什么都没有。
任何帮助将不胜感激!
解决方案
@Ricco D 绝对正确,我打印的结果不正确......
当您尝试转录较长的文件时,Google Speech to Text 将根据检测到语音暂停的时间来分解您的转录。
您的 response.results[] 数组将包含多个条目,您需要循环这些条目以打印完整的成绩单。
有关更多详细信息,请参阅文档: https ://cloud.google.com/speech-to-text/docs/basics#responses
推荐阅读
- javascript - 比多次调用 setState 更好的方法来处理无线电组形式?
- templates - IntelliJ 模板函数将变量名转换为常量变量名(大写带下划线)
- angularjs - 将`$scope.$broadcast('test', false);`中的false改为true` 视图
- javascript - JavaScript setTimeout 无递归无限循环
- ios - 为什么 QR Scanner Ionic 插件会产生错误?
- typescript - 在 TypeScript 中使用映射类型时更严格的联合类型
- python - GTK、Glade 和 Python 使用 connect_signals 连接来自多个类的处理程序
- python - lock.acquire 是否阻塞非关键部分中的进程
- python - 列表理解语法错误
- php - 提交 Google 自定义搜索