Last active
March 3, 2017 21:33
-
-
Save nfriedly/e78b5869cf406dddca9d8140fcd64923 to your computer and use it in GitHub Desktop.
Extract transaction ID from IBM Watson Node.js SDK Speech to Text RecognizeStream (WebSocket)
This file contains hidden or 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'; | |
const SpeechToTextV1 = require('watson-developer-cloud/speech-to-text/v1'); | |
require('dotenv').config({silent: true}); // optional, loads credentials from a .env file | |
const fs = require('fs'); | |
const speech_to_text = new SpeechToTextV1({ | |
// defaults to env properties if these are unset | |
// username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE', | |
// password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE' | |
}); | |
// create the stream | |
const recognizeStream = speech_to_text.createRecognizeStream({ | |
content_type: 'audio/wav' | |
}); | |
// pipe in some audio | |
fs.createReadStream(__dirname + '/resources/speech.wav').pipe(recognizeStream); | |
// notes: | |
// 1. Requires [email protected] or later | |
// 2. It won't resolve until after you begin sending audio | |
// 3. This won't work in browsers because WebSocket headers are not exposed in browsers | |
recognizeStream.getTransactionId() | |
.then( transId => { | |
console.log('transaction id', transId); | |
}).catch( err => { | |
console.log('error getting transaction id', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment