繁体   English   中英

IBM Watson语音到文本的“流”是什么?

[英]What is 'stream' with IBM Watson Speech-to-text?

我找不到方法stream.onstream.recognizeStream.on 我已经搜索了文档API 我目前的具体问题是关于诺言,例如,这不起作用:

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开始发送数据流之后再也看不到这些值。 我希望诺言能解决这个问题,但是没有运气。 :-(

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

如您所见,API参考中使用了以下示例, recognizeStream用于“语音到文本”的实例,并用于识别您发送的语音,即createRecognizeStream 函数 Node SDK

您可以使用其他变量,具体取决于您,但是,您需要将语音实例化为文本并调用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));
};
  • 参见官方演讲,使用语音对Node.js进行文字处理
  • 项目使用语音到文本和Node.js的由IBM开发者

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM