首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Watson Speech-to-text JS SDK立即关闭WebSocket

使用Watson Speech-to-text JS SDK立即关闭WebSocket
EN

Stack Overflow用户
提问于 2018-07-20 02:53:02
回答 0查看 151关注 0票数 1

尝试使用提供的演示中的代码,使用来自https://github.com/watson-developer-cloud/speech-javascript-sdk的最新watson-speech.js .js

代码语言:javascript
复制
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已处于关闭或关闭状态。

使用Chrome并在本地测试。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51429963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档