我正在瀏覽器或控制檯中看到單詞副本,但我沒有看到諸如{'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();
};
};
謝謝,成功了!你能提出我的問題嗎? –