我正在浏览器或控制台中看到单词副本,但我没有看到诸如{'state': 'listening'}
之类的消息。更重要的是,我没有看到如{"results": [{"alternatives": [{"transcript": "name the mayflower "}],"final": true}],"result_index": 0}
的结果。IBM Watson语音到文本JavaScript SDK:如何获取消息?
我读了RecognizeStream documentation,并试图将此代码:
stream.on('message', function(message) {
console.log(message);
});
,但不起作用。我在true
和false
都试过object_mode
,但输出结果是一样的。
下面是我使用的全码:
document.querySelector('#button').onclick = function() {
var stream = WatsonSpeech.SpeechToText.recognizeMicrophone({
token: token,
model: 'en-US_BroadbandModel',
keywords: ["Colorado"],
keywords_threshold: 0.50,
word_confidence: true,
// outputElement: '#output' // send text to browser instead of console
object_mode: false
});
stream.setEncoding('utf8'); // get text instead of Buffers for on data events
stream.on('data', function(data) { // send text to console instead of browser
console.log(data);
});
stream.on('error', function(err) {
console.log(err);
});
document.querySelector('#stop').onclick = function() {
stream.stop();
};
};
谢谢,成功了!你能提出我的问题吗? –