【发布时间】:2016-03-11 15:13:53
【问题描述】:
使用 Watson Speech to Text 服务 如何提取 createRecognizeStream() 方法返回的值?
这里是示例代码的一部分。我试图在终端中查看临时结果,但我得到的只是这个。如何设置显示结果的选项?
{ results: [ { alternatives: [Object], final: false } ],
result_index: 0 }
{ results: [ { alternatives: [Object], final: false } ],
result_index: 0 }
{ results: [ { alternatives: [Object], final: false } ]...
它们应该看起来像这样:
{
"results": [
{
"alternatives": [
{
"timestamps": [
[
"Here",
0.08,
0.63
],
[
"I",
0.66,
0.95
],
[
"Open",
0.95,
1.07
],
[
"a",
1.07,
1.33
],
[
"strong",
1.33,
1.95
],
[
"group",
2.03,
2.18
],
[
"of",
2.18,
2.72
],
[
示例代码:
// create the stream
var recognizeStream = speech_to_text.createRecognizeStream(params);
// pipe in some audio
fs.createReadStream(filepath).pipe(recognizeStream);;
// and pipe out the transcription
recognizeStream.pipe(fs.createWriteStream('transcriptions/transcription-' + path.basename(filepath) + '.txt'));
// listen for 'data' events for just the final text
// listen for 'results' events to get the raw JSON with interim results, timings, etc.
recognizeStream.setEncoding('utf8');// to get strings instead of Buffers from `data` events
['data','results', 'error', 'connection-close'].forEach(function(eventName) {
//JSON.stringify(eventName, null, 2)
//fs.writeFile('./transcript.txt', JSON.stringify(transcript), function(err) {if(err){return console.log('err')}});
recognizeStream.on('results', console.log.bind(console, ''));
});
【问题讨论】:
-
疯狂猜测。每 http 100-continue .. 您的标准输出表示连接已启动并等待输入(音频流),但是,连接上没有写入任何会产生结果的内容。查看 API。在 curl 上调用它以观察它在实际流上的工作。然后实施 cli 上的工作。
-
流确实在transcription.text 文件上输出正确的转录文本。它只是在监听事件时不输出正确的中间结果
-
连续模式是你想要的。在 api 文档中查找方法
标签: node.js ibm-cloud speech-to-text ibm-watson