【问题标题】:No timestamps in Watson speech-to-textWatson 语音转文本中没有时间戳
【发布时间】:2016-07-18 23:14:39
【问题描述】:

我正在使用 Watson-Developer-Cloud 模块,并附上示例:https://www.npmjs.com/package/watson-developer-cloud#speech-to-text

很遗憾,我的所有选项似乎都不起作用:

timestamps: true, profanity_filter: false, word_confidence:true

我是否在正确的地方传递它们?

var watson = require('watson-developer-cloud');
var fs = require('fs');

var speech_to_text = watson.speech_to_text({
  url: "https://stream.watsonplatform.net/speech-to-text/api",
  username: 'xxxxx',
  password: 'xxxxx',
  version: 'v1'
});


fs.createReadStream('./resources/speech.wav')
  .pipe(speech_to_text.createRecognizeStream({ content_type: 'audio/l16; rate=44100', timestamps: true, profanity_filter: false, word_confidence:true }))
  .pipe(fs.createWriteStream('./transcription2.txt'));

我正在取回成绩单,但我想要时间戳和置信度分数。这是我返回的示例:

“五个电话就可以度过愉快的 **** 周”

如您所见,仍然没有时间戳、没有置信度分数和脏话被过滤掉。

【问题讨论】:

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


    【解决方案1】:

    我会查看识别流事件以更好地控制输出,例如:

    // Create the stream.
    var recognizeStream = speech_to_text.createRecognizeStream(params);
    
    // Pipe in the audio.
    fs.createReadStream('audio-file.wav').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.
    recognizeStream.on('data', function(event) { onEvent('Data:', event); });
    recognizeStream.on('results', function(event) { onEvent('Results:', event); });
    recognizeStream.on('error', function(event) { onEvent('Error:', event); });
    recognizeStream.on('close-connection', function(event) { onEvent('Close:', event); });
    
    // Displays events on the console.
    function onEvent(name, event) {
        console.log(name, JSON.stringify(event, null, 2));
    };
    

    API documentation 也有一个例子。

    【讨论】:

    • 谢谢,感谢您的帮助。我从 'recognizeStream.on('results', function(event) { onEvent('Results:', event); });' 得到了正确的输出但我不太了解recognizeStream.pipe api。我如何将结果写入文件而不是数据?
    • 在您的事件处理程序中,您只需使用 Node.js 函数 fs.writeFile(file, data[, options], callback)。详情见nodejs.org/api/…
    猜你喜欢
    • 1970-01-01
    • 2019-04-22
    • 2019-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多