Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extract transaction ID from IBM Watson Node.js SDK Speech to Text RecognizeStream (WebSocket)
'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 watson-developer-cloud@2.24.0 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
You can’t perform that action at this time.