简体   繁体   English

IBM Watson Speech-to-Text JavaScript SDK:如何获取消息?

[英]IBM Watson Speech-to-Text JavaScript SDK: how to get messages?

I'm seeing the word transcriptions, either in the browser or in the console, but I'm not seeing the messages such as {'state': 'listening'} .我在浏览器或控制台中看到了转录这个词,但我没有看到诸如{'state': 'listening'} More importantly, I'm not seeing the results such as {"results": [{"alternatives": [{"transcript": "name the mayflower "}],"final": true}],"result_index": 0} .更重要的是,我没有看到诸如{"results": [{"alternatives": [{"transcript": "name the mayflower "}],"final": true}],"result_index": 0} .

I read the RecognizeStream documentation and tried this code:我阅读了RecognizeStream 文档并尝试了以下代码:

stream.on('message', function(message) {
    console.log(message);
  });

but that doesn't work.但这不起作用。 I tried object_mode in both true and false but the output was the same.我在truefalse中都尝试了object_mode ,但输出是一样的。

Here's the full code that I'm using:这是我正在使用的完整代码:

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();
  };
};

The recognizeMicrophone() method is a helper that chains together a number of streams. recognizeMicrophone()方法是一个将多个流链接在一起的助手。 The message event is fired on one of the streams in the middle. message事件在中间的流之一上触发。 But, you can get access to that one at stream.recognizeStream - it's always attached to the last one in the chain in order to support cases like this.但是,您可以在stream.recognizeStream访问那个 - 它总是附加到链中的最后一个以支持这样的情况。

So, in your code, it should look something like this:因此,在您的代码中,它应该如下所示:

stream.recognizeStream.on('message', function(frame, data) {
  console.log('message', frame, data)
});

However, that is mainly there for debugging.但是,这主要用于调试。 The results JSON should be emitted on the data event, if you set objectMode: true and don't call stream.setEncoding('utf8');如果您设置objectMode: true并且调用stream.setEncoding('utf8'); ,则结果 JSON 应该在data事件上发出stream.setEncoding('utf8'); . .

(This is somewhat different from Watson Node.js SDK, if you're familiar with it's behavior. There are plans to unify the two, but never enough time...) (这与 Watson Node.js SDK 有点不同,如果您熟悉它的行为。有计划将两者统一,但时间不够...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于语音转文本WebSocket的IBM Watson JavaScript SDK - IBM Watson JavaScript SDK for Speech-To-Text WebSocket Issue IBM Watson语音到文本发送麦克风数据关闭连接 - IBM Watson Speech-to-Text sending microphone data closes connection 如何使用 javascript 在浏览器中运行 IBM Watson 文本转语音 - How to run IBM Watson Text to speech in browser using javascript ibm沃森语音转换为纯jQuery / JavaScript的文本api - ibm watson speech to text api for pure jquery/javascript 如何使用 AIFF 文件进行语音转文本 - How to get speech-to-text working with an AIFF file 针对盲人的JavaScript语音转文本 - JavaScript Speech-to-Text for blind people 如何优雅地结束 Google Speech-to-Text 流识别并取回待处理的文本结果? - How to end Google Speech-to-Text streamingRecognize gracefully and get back the pending text results? Chrome中使用javascript语音转换文字无法识别任何内容 - Speech-to-text with javascript in Chrome doesn't recognize anything 对于像https://watson-speech.mybluemix.net/microphone-streaming.html这样的简单语音转文本应用程序,是否有一些libcurl脚本? - Is there a bit of libcurl script for a simple speech-to-text application like this https://watson-speech.mybluemix.net/microphone-streaming.html? 语音到文本识别不准确 - Speech-to-text Recognition is not accurate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM