谷歌语音识别api v2中期结果

时间:2016-10-07 10:36:53

标签: node.js speech-recognition google-speech-api

我一直在使用节点js npm谷歌语音识别API v2 google-speech-api https://www.npmjs.com/package/google-speech-api 它正在发挥作用,但我需要获得"中期结果"。

如何获得正在处理的音频的中间结果。我在线搜索但无法找到有用的信息并使其有效。

以下是我目前正在处理的代码:

var speech = require('google-speech-api');
var fs              = require('fs');

var opts = {
  file: 'amy_16.wav',
  key: 'xxxx',
};

speech(opts, function (err, results) {
 console.log(JSON.stringify(results));
 // [{result: [{alternative: [{transcript: '...'}]}]}]
});

1 个答案:

答案 0 :(得分:1)

看起来您没有使用流媒体识别功能。为了获得部分结果,您需要使用speech.createRecognizeStream并将interimResults配置标志设置为true。例如:

var request = {
    config: {
        encoding: 'LINEAR16',
        sampleRate: 16000
    },
    singleUtterance: false,
    interimResults: true
};

fs.createReadStream('amy_16.wav')
    .on('error', console.error)
    .pipe(speech.createRecognizeStream(request))
    .on('error', console.error)
    .on('data', function(data) {
        //do something with the data
        console.log(data)
});

不确定您要实现的目标,但要简化您可能需要查看的内容Sonus。它是一个始终聆听的语音识别框架,它支持开箱即用的部分结果。它也做热门词检测。免责声明:这是我的项目

相关问题