【问题标题】:What is 'stream' with IBM Watson Speech-to-text?IBM Watson Speech-to-text 中的“流”是什么?
【发布时间】:2017-09-08 16:09:03
【问题描述】:

我找不到方法 stream.onstream.recognizeStream.on 的文档。我搜索了documentationAPI。我此时的具体问题是关于承诺,例如,这不起作用:

stream.on('data', function(transcribedSpeech) {
  console.log(transcribedSpeech);
})
.then(function() {
  console.log("Then...");
  this.transcribedSpeech = transcribedSpeech;
})
.catch(function() {
  console.log("Error");
});

错误是TypeError: stream.on(...).then is not a function。我正在尝试为 IBM Watson Speech-to-text 提供 Angularjs 服务。一切正常,即来自 Watson 的消息、脚本、关键字等正在记录到控制台,但我无法从服务获取数据流到控制器。当我从控制器调用服务时,控制器只看到参数的初始值 (undefined),而在 Watson 开始发送数据流之后,就再也看不到这些值了。我希望一个承诺能解决这个问题,但没有运气。 :-(

【问题讨论】:

    标签: node.js speech-to-text ibm-watson


    【解决方案1】:

    我不是语音转文本方面的专家,但几个月前我使用 API 参考和 IBM 的项目做了一个示例。

    如您所见,API 参考中使用了以下示例,recognizeStream 用于 Speech to text 的实例,用于识别您发送的语音,createRecognizeStream function @987654322 @。

    您可以使用其他变量,这取决于您,但是,您需要将语音实例化为文本并调用 createRecogniseStream 来识别语音事件。

    服务会在设置 utf8 后转录您的文件,并添加文本识别的转录文件,如下例:

    var SpeechToTextV1 = require('watson-developer-cloud/speech-to-text/v1');
    var fs = require('fs');
    
    var speech_to_text = new SpeechToTextV1 ({
      username: '{username}',
      password: '{password}'
    });
    
    var params = {
      model: 'en-US_BroadbandModel',
      content_type: 'audio/flac',
      'interim_results': true,
      'max_alternatives': 3,
      'word_confidence': false,
      timestamps: false,
      keywords: ['colorado', 'tornado', 'tornadoes'],
      'keywords_threshold': 0.5
    };
    
    // Create the stream with the instancie of speech to text and access the function to Recognise the speech.
    var recognizeStream = speech_to_text.createRecognizeStream(params);
    
    // Pipe in the audio in the parameter recognizeStream.
    fs.createReadStream('audio-file.flac').pipe(recognizeStream);
    
    // Pipe out the transcription to a file.
    recognizeStream.pipe(fs.createWriteStream('transcription.txt'));
    
    // Get strings instead of buffers from 'data' events.
    recognizeStream.setEncoding('utf8');
    
    // Listen for events using the paramter after set utf8 and the transcrit file.
    recognizeStream.on('results', function(event) { onEvent('Results:', event); });
    recognizeStream.on('data', function(event) { onEvent('Data:', event); });
    recognizeStream.on('error', function(event) { onEvent('Error:', event); });
    recognizeStream.on('close', function(event) { onEvent('Close:', event); });
    recognizeStream.on('speaker_labels', function(event) { onEvent('Speaker_Labels:', event); });
    
    // Displays events on the console.
    function onEvent(name, event) {
      console.log(name, JSON.stringify(event, null, 2));
    };
    
    • 请参阅Official 参考,使用带有 Node.js 的 Speech to text
    • Project 由 IBM 开发人员使用 Speech to text 和 Node.js 提供

    【讨论】:

      猜你喜欢
      • 2017-07-28
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多