Skip to content

Commit bc15df2

Browse files
committed
added message event to recognize stream for any data recieved over the wire
1 parent 3e8f459 commit bc15df2

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

speech-to-text/recognize-file.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ module.exports = function recognizeFile(options) { // eslint-disable-line comple
150150
}
151151
}
152152

153+
// expose the original stream to for debugging (and to support the JSON tab on the STT demo)
154+
if (stream !== recognizeStream) {
155+
stream.recognizeStream = recognizeStream;
156+
}
157+
158+
153159
return stream;
154160
};
155161

speech-to-text/recognize-microphone.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,13 @@ module.exports = function recognizeMicrophone(options) {
178178
}
179179
});
180180

181-
// add a stop button to whatever the final stream ends up being
182181
if (stream !== recognizeStream) {
182+
// add a stop button to whatever the final stream ends up being
183183
stream.stop = recognizeStream.stop.bind(recognizeStream);
184-
}
185184

185+
// expose the original stream to for debugging (and to support the JSON tab on the STT demo)
186+
stream.recognizeStream = recognizeStream;
187+
}
186188

187189
return stream;
188190
};

speech-to-text/recognize-stream.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ RecognizeStream.prototype.initialize = function() {
285285
}
286286

287287
socket.onmessage = function(frame) {
288+
/**
289+
* Emit any messages received over the wire, mainly used for debugging.
290+
*
291+
* @event RecognizeStream#message
292+
* @param {Object} message - frame object with a data attribute that's either a string or a Buffer/TypedArray
293+
*/
294+
this.emit('message', frame);
295+
288296
if (typeof frame.data !== 'string') {
289297
return emitError('Unexpected binary data received from server', frame);
290298
}
@@ -336,14 +344,20 @@ RecognizeStream.prototype.initialize = function() {
336344

337345
RecognizeStream.prototype.sendJSON = function sendJSON(msg) {
338346
/**
347+
* Emits any JSON object sent to the service from the client. Mainly used for debugging.
339348
* @event RecognizeStream#send-json
340-
* @param {Object} msg - the raw JSON sent to Watson - sometimes useful for debugging
349+
* @param {Object} msg
341350
*/
342351
this.emit('send-json', msg);
343352
return this.socket.send(JSON.stringify(msg));
344353
};
345354

346355
RecognizeStream.prototype.sendData = function sendData(data) {
356+
/**
357+
* Emits any Binary object sent to the service from the client. Mainly used for debugging.
358+
* @event RecognizeStream#send-data
359+
* @param {Object} msg
360+
*/
347361
this.emit('send-data', data);
348362
return this.socket.send(data);
349363
};

0 commit comments

Comments
 (0)