Using Watson Speech to Text Services How to extract the values that return from the createRecognizeStream() method?
Here is a chunk of the sample code. I am trying to see in the terminal the interim results but all i get is this. How do I set the options for the results to appear?
{ results: [ { alternatives: [Object], final: false } ],
result_index: 0 }
{ results: [ { alternatives: [Object], final: false } ],
result_index: 0 }
{ results: [ { alternatives: [Object], final: false } ]...
they should look like this:
{
"results": [
{
"alternatives": [
{
"timestamps": [
[
"Here",
0.08,
0.63
],
[
"I",
0.66,
0.95
],
[
"Open",
0.95,
1.07
],
[
"a",
1.07,
1.33
],
[
"strong",
1.33,
1.95
],
[
"group",
2.03,
2.18
],
[
"of",
2.18,
2.72
],
[
sample code:
// create the stream
var recognizeStream = speech_to_text.createRecognizeStream(params);
// pipe in some audio
fs.createReadStream(filepath).pipe(recognizeStream);;
// and pipe out the transcription
recognizeStream.pipe(fs.createWriteStream('transcriptions/transcription-' + path.basename(filepath) + '.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) {
//JSON.stringify(eventName, null, 2)
//fs.writeFile('./transcript.txt', JSON.stringify(transcript), function(err) {if(err){return console.log('err')}});
recognizeStream.on('results', console.log.bind(console, ''));
});