Created
August 1, 2015 03:42
-
-
Save germanattanasio/359580d99ea22f47c6ba to your computer and use it in GitHub Desktop.
Using Speech to Text with and shows interim results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// replace username and password with speech to text credentials | |
// audio.wav can be found here: https://github.com/watson-developer-cloud/nodejs-wrapper/blob/master/test/resources/audio.wav?raw=true | |
var watson = require('watson-developer-cloud'), | |
fs = require('fs'); | |
var speechToText = watson.speech_to_text({ | |
password: '<username>', | |
username: '<password>', | |
version: 'v1' | |
}); | |
var noop = function(){}; | |
var observeResult = function(err, transcript) { | |
if (err){ | |
console.log(err); | |
return; | |
} | |
// print the interim results | |
console.log(JSON.stringify(transcript, null, 2)); | |
}; | |
speechToText.createSession({}, function(err, session){ | |
if (err){ | |
console.log('error:', err); | |
return; | |
} | |
var request = speechToText.recognizeLive({ | |
content_type: 'audio/l16;rate=44100', | |
continuous: true, | |
word_confidence: true, | |
interim_results: true, | |
session_id: session.session_id, | |
cookie_session: session.cookie_session }, noop); | |
// call observe result to get intermin results | |
speechToText.observeResult({ | |
interim_results: true, | |
session_id: session.session_id, | |
cookie_session: session.cookie_session }, observeResult); | |
// pipe the audio to the request | |
// once the stream is consumed it will call request.end() | |
fs.createReadStream('audio.wav').pipe(request); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output is: