I have been working on google speech recognition API v2 using node js npm google-speech-api https://www.npmjs.com/package/google-speech-api it is working, but i need to get the "interim results".
How can i get the interim results of the audio being processing. I have searched online but not able to find helpful information and make it work.
Below is the code i am working on currently:
var speech = require('google-speech-api');
var fs = require('fs');
var opts = {
file: 'amy_16.wav',
key: 'xxxx',
};
speech(opts, function (err, results) {
console.log(JSON.stringify(results));
// [{result: [{alternative: [{transcript: '...'}]}]}]
});
Looks like you aren't using streaming recognition. In order to get partial results you'll need to use speech.createRecognizeStream
and set the interimResults
config flag to true. For example:
var request = {
config: {
encoding: 'LINEAR16',
sampleRate: 16000
},
singleUtterance: false,
interimResults: true
};
fs.createReadStream('amy_16.wav')
.on('error', console.error)
.pipe(speech.createRecognizeStream(request))
.on('error', console.error)
.on('data', function(data) {
//do something with the data
console.log(data)
});
Not sure what you are trying to achieve, but to simplify things you might want to check out Sonus. It's an always listening speech recognition framework and it supports partial results out of the box. It also does hotword detection. Disclaimer: this is my project