Watson IBM演讲文本:no interim_result(Node.JS)

时间:2015-07-27 09:27:54

标签: node.js speech-recognition speech-to-text ibm-watson

我正在尝试使用node.js

获取interim_results
var params = {
audio: fs.createReadStream('./out.wav'),
content_type: 'audio/l16;rate=16000',
continuous: true,
interim_results: true,
word_confidence: true
};

我使用speech_to_text.createSession创建会话,然后尝试启动recognize功能:

function recognize(params,session_id,cookie_session) {
setInterval(function(){ observe_results(session_id,cookie_session) }, 1000);
speech_to_text.recognize(params, function(err, transcript) {
    if (err) {
        console.log(err);
    }
    else {
        console.log("OK")
        console.log(JSON.stringify(transcript, null, 2));
        fs.writeFile('./transcript.txt', JSON.stringify(transcript), function(err) {if(err){return console.log('err')}});
    }
});}

但我只收到最后一个转录,而不是interim_results。 提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

更新:11/4 : 从v1.0开始,watson-developer-cloud npm模块支持websockets。

请参阅:how to create a blob in node.js to be used in a websocket?

原始回答
您正在拨打recognize而不是recognizeLive

请参阅以下示例:

var watson = require('watson-developer-cloud'),
  fs = require('fs');

var speechToText = watson.speech_to_text({
 password: '<password>',
 username: '<username>',
 version: 'v1'
});

var noop = function(){};

var observeResult = function(err, transcript) {
  if (err){
    console.log(err);
    return;
  }
  // print the transcript
  console.log(JSON.stringify(transcript, null, 2));
};

speechToText.createSession({}, function(err, session){
  if (err){
    console.log('error:', err);
    return;
  }

  var request = speechToText.recognizeLive({
    content_type: 'audio/l16;rate=44100',
    continuous: true,
    word_confidence: true,
    interim_results: true,
    session_id: session.session_id,
    cookie_session: session.cookie_session }, noop);

  // call observe result to get intermin results
  speechToText.observeResult({
    interim_results: true,
    session_id: session.session_id,
    cookie_session: session.cookie_session }, observeResult);

  // pipe the audio to the request
  // once the stream is consumed it will call request.end()
  fs.createReadStream('audio.wav').pipe(request);
});

替换usernamepassword,请使用此audio

我写了glist以供将来参考。它还包含使用上述音频时的输出。