【发布时间】:2018-07-19 18:53:02
【问题描述】:
尝试使用提供的演示中的此代码,使用来自https://github.com/watson-developer-cloud/speech-javascript-sdk 的最新 watson-speech.js:
document.querySelector('#button').onclick = function () {
fetch('myserverurl/api/token')
.then(function(response) {
return response.text();
}).then(function (token) {
var stream = WatsonSpeech.SpeechToText.recognizeMicrophone({
token: token,
outputElement: '#output' // CSS selector or DOM Element
});
stream.on('error', function(err) {
console.log(err);
});
document.querySelector('#stop').onclick = function() {
stream.stop();
};
}).catch(function(error) {
console.log(error);
});
};
尝试在 Chrome 控制台中启动连接时立即收到此错误: WebSocket 已经处于 CLOSING 或 CLOSED 状态。
使用 Chrome 并在本地进行测试。
【问题讨论】: