從v1.0開始(仍然在beta)watson-developer-cloud npm模塊支持websockets。
npm install [email protected]
認識到自己的wav文件:
var watson = require('watson-developer-cloud');
var fs = require('fs');
var speech_to_text = watson.speech_to_text({
username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE',
version: 'v1',
});
// create the stream
var recognizeStream = speech_to_text.createRecognizeStream({ content_type: 'audio/wav' });
// pipe in some audio
fs.createReadStream('audio-to-recognize.wav').pipe(recognizeStream);
// and pipe out the transcription
recognizeStream.pipe(fs.createWriteStream('transcription.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) {
recognizeStream.on(eventName, console.log.bind(console, eventName + ' event: '));
});
查看更多例子here。
您能否在這裏添加一段代碼導致您在上面提到的錯誤? –