new RecognizeStream(options)
pipe()-able Node.js Duplex stream - accepts binary audio and emits text/objects in it's data events.
Uses WebSockets under the hood. For audio with no recognizable speech, no data events are emitted.
By default, only finalized text is emitted in the data events, however when objectMode/readableObjectMode and interim_results are enabled, both interim and final results objects are emitted.
WriteableElementStream uses this, for example, to live-update the DOM with word-by-word transcriptions.
Note that the WebSocket connection is not established until the first chunk of data is recieved. This allows for auto-detection of content type (for wav/flac/opus audio).
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
Methods
stop()
Prevents any more audio from being sent over the WebSocket and gracefully closes the connection.
Additional data may still be emitted up until the end event is triggered.
Events
close
Parameters:
| Name | Type | Description |
|---|---|---|
reasonCode |
Number | |
description |
String |
data
Finalized text
Parameters:
| Name | Type | Description |
|---|---|---|
transcript |
String |
data
Object with interim or final results, possibly including confidence scores, alternatives, and word timing.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object |
error
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
String | custom error message |
|
frame |
* |
<optional> |
unprocessed frame (should have a .data property with either string or binary data) |
err |
Error |
<optional> |
listening
Emitted when the Watson Service indicates readieness to transcribe audio. Any audio sent before this point will be buffered until now.
message
Emit any messages received over the wire, mainly used for debugging.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
message |
Object | frame object with a data attribute that's either a string or a Buffer/TypedArray |
|
data |
Object |
<optional> |
parsed JSON object (if possible); |
open
emitted once the WebSocket connection has been established
send-data
Emits any Binary object sent to the service from the client. Mainly used for debugging.
Parameters:
| Name | Type | Description |
|---|---|---|
msg |
Object |
send-json
Emits any JSON object sent to the service from the client. Mainly used for debugging.
Parameters:
| Name | Type | Description |
|---|---|---|
msg |
Object |
stop
Event emitted when the stop method is called. Mainly for synchronising with file reading and playback.