I have been getting stuck on my speech_to_text test for a couple of days, any advice would be appreciated:
WARNING: This method of instantiating the Watson services has been deprecated beginning with Version 3.0.0 of the Node SDK. Please refer to the Node SDK documentation for information on how to instantiate Watson services. This form of service instantiaion will be removed in a future release of the SDK. start record Error: Watson Speech to Text RecognizeStream: the results event was deprecated. Please set {objectMode: true} and listen for the 'data' event instead. Pass {silent: true} to disable this message. at RecognizeStream. (/home/pi/workspace/rapiro-iotf/node_modules/watson-developer-cloud/lib/recognize-stream.js:128:33) at RecognizeStream.emit (events.js:180:13) at _addListener (events.js:209:14) at RecognizeStream.addListener (events.js:258:10) at RecognizeStream.Readable.on (_stream_readable.js:784:35) at stt (/home/pi/workspace/rapiro-iotf/mictest.js:32:18) at Object. (/home/pi/workspace/rapiro-iotf/mictest.js:8:2) at Module._compile (internal/modules/cjs/loader.js:654:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) at Module.load (internal/modules/cjs/loader.js:566:32) Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono
Here's my source code:
var watson = require('watson-developer-cloud');
var cp = require('child_process');
var mic;
var fs = require('fs');
mic = cp.spawn('arecord', ['--device=plughw:1,0', '--format=S16_LE', '--rate=44100',
'--channels=1']); //, '--duration=10'
mic.stderr.pipe(process.stderr);
stt();
function stt() {
console.log("openCMDS");
var speech_to_text = watson.speech_to_text({
username: 'myusername',
password: 'mypassword',
version: 'v1'
});
var params = {
content_type: 'audio/wav',
model:'zh-CN_BroadbandModel',
continuous: true,
objectMode: true,
inactivity_timeout: -1
};
recognizeStream = speech_to_text.createRecognizeStream(params);
mic.stdout.pipe(require('fs').createWriteStream('test.wav'));
mic.stdout.pipe(recognizeStream);
recognizeStream.setEncoding('utf8');
console.log("start record");
recognizeStream.on('results', function(data){
if(data.results[0] && data.results[0].final && data.results[0].alternatives){
console.log(JSON.stringify(data, null, 2));
}
});
}
Answer by Joe_Yang (44) | Sep 09, 2018 at 08:13 AM
the error is gone after following new stt api, In particular I was trying to get the microphone streamed directly to the speechToText service. I believe this is the most common way of using mic, not piping it into a .wav and then stream the .wav file to stt., any advice ?
var mic;
var SpeechToTextV1 = require('watson-developer-cloud/speech-to-text/v1');
var fs = require('fs');
var watson = require('watson-developer-cloud');
var cp = require('child_process');
mic = cp.spawn('arecord', ['--device=plughw:1,0', '--format=S16_LE', '--rate=44100', '--channels=1']); //, '--duration=10'
mic.stderr.pipe(process.stderr);
stt();
function stt() {
console.log("openCMDS");
var speech_to_text = new SpeechToTextV1({
username: '',
password: ''
});
var params = {
content_type: 'audio/wav',
model: 'zh-CN_BroadbandModel',
continuous: true,
inactivity_timeout: -1
};
recognizeStream = speech_to_text.createRecognizeStream(params);
mic.stdout.pipe(recognizeStream);
//mic.stdout.pipe(require('fs').createWriteStream('test.wav'));
// Pipe in the audio.
fs.createReadStream('test.wav').pipe(recognizeStream);
recognizeStream.pipe(fs.createWriteStream('transcription.txt'));
recognizeStream.setEncoding('utf8');
console.log("start record");
recognizeStream.on('data', function(event) { onEvent('Data:', event); });
recognizeStream.on('error', function(event) { onEvent('Error:', event); });
recognizeStream.on('close', function(event) { onEvent('Close:', event); });
// Display events on the console.
function onEvent(name, event) {
console.log(name, JSON.stringify(event, null, 2));
}
}
Answer by Joe_Yang (44) | Sep 11, 2018 at 11:16 PM
I also created a question on stackoverflow: https://stackoverflow.com/questions/52286957/how-to-get-the-microphone-streamed-directly-to-the-watson-speechtotext-service
node.js - speech to text deprecated error 0 Answers
watson speech to text error on node.js 0 Answers
After Digression how to don't ask previous question and continue further where stopped before? 2 Answers
Connection problem using web API via z/OS Client Web Enablement Toolkit using PL1 0 Answers
[IBM Watson] 403 authentication error when connecting to a workspace 1 Answer