Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RecognizeStream

pipe()-able Node.js Readable/Writeable stream - accepts binary audio and emits text in its data events. Also emits results events with interim results and other data.

Cannot be instantiated directly, instead created by calling #recognizeUsingWebSocket()

Uses WebSockets under the hood. For audio with no recognizable speech, no data events are emitted.

param

Hierarchy

  • Duplex
  • Duplex
    • RecognizeStream

Implements

  • ReadableStream
  • Writable
  • ReadableStream
  • Writable

Index

Constructors

constructor

  • pipe()-able Node.js Duplex stream - accepts binary audio and emits text/objects in it's data events. 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).

    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).

    constructor

    Parameters

    Name Type Attribute Description
    opts DuplexOptions Optional

    Returns RecognizeStream

Properties

_writableState

_writableState: WritableState

destroyed

destroyed: boolean

readable

readable: boolean

Readonly readableEncoding

readableEncoding: BufferEncoding | null

Readonly readableEnded

readableEnded: boolean

Readonly readableFlowing

readableFlowing: boolean | null

Readonly readableHighWaterMark

readableHighWaterMark: number

Readonly readableLength

readableLength: number

readableObjectMode

readableObjectMode: boolean

Readonly writable

writable: boolean

Readonly writableCorked

writableCorked: number

Readonly writableEnded

writableEnded: boolean

Readonly writableFinished

writableFinished: boolean

Readonly writableHighWaterMark

writableHighWaterMark: number

Readonly writableLength

writableLength: number

Readonly writableObjectMode

writableObjectMode: boolean

Static ERROR_UNRECOGNIZED_FORMAT

ERROR_UNRECOGNIZED_FORMAT: string = "UNRECOGNIZED_FORMAT"

Static WEBSOCKET_CONNECTION_ERROR

WEBSOCKET_CONNECTION_ERROR: string = "WebSocket connection error"

Methods

[Symbol.asyncIterator]

  • [Symbol.asyncIterator](): AsyncIterableIterator<any>

_destroy

  • _destroy(error: Error | null, callback: function): void
  • Parameters

    Name Type Attribute Description
    error Error | null

    callback function

    Returns void

_final

  • _final(callback: function): void

_read

  • _read(size: number): void

_write

  • _write(chunk: any, encoding: string, callback: function): void
  • Parameters

    Name Type Attribute Description
    chunk any

    encoding string

    callback function

    Returns void

Optional _writev

  • _writev(chunks: Array<object>, callback: function): void
  • Parameters

    Name Type Attribute Description
    chunks Array<object>

    callback function

    Returns void

addListener

  • addListener(event: "close", listener: function): this
  • addListener(event: "data", listener: function): this
  • addListener(event: "end", listener: function): this
  • addListener(event: "error", listener: function): this
  • addListener(event: "pause", listener: function): this
  • addListener(event: "readable", listener: function): this
  • addListener(event: "resume", listener: function): this
  • addListener(event: string | symbol, listener: function): this
  • Event emitter The defined events on documents including:

    1. close
    2. data
    3. end
    4. error
    5. pause
    6. readable
    7. resume

    Parameters

    Name Type Attribute Description
    event "close"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "data"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "end"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "error"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "pause"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "readable"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "resume"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event string | symbol

    listener function

    Returns this

cork

  • cork(): void

destroy

  • destroy(error?: Error): void

emit

  • emit(event: "close"): boolean
  • emit(event: "data", chunk: any): boolean
  • emit(event: "end"): boolean
  • emit(event: "error", err: Error): boolean
  • emit(event: "pause"): boolean
  • emit(event: "readable"): boolean
  • emit(event: "resume"): boolean
  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    Name Type Attribute Description
    event "close"

    Returns boolean

  • Parameters

    Name Type Attribute Description
    event "data"

    chunk any

    Returns boolean

  • Parameters

    Name Type Attribute Description
    event "end"

    Returns boolean

  • Parameters

    Name Type Attribute Description
    event "error"

    err Error

    Returns boolean

  • Parameters

    Name Type Attribute Description
    event "pause"

    Returns boolean

  • Parameters

    Name Type Attribute Description
    event "readable"

    Returns boolean

  • Parameters

    Name Type Attribute Description
    event "resume"

    Returns boolean

  • Parameters

    Name Type Attribute Description
    event string | symbol

    args any[] Rest

    Returns boolean

end

  • end(cb?: function): void
  • end(chunk: any, cb?: function): void
  • end(chunk: any, encoding?: string, cb?: function): void
  • Parameters

    Name Type Attribute Description
    cb function Optional

    Returns void

  • Parameters

    Name Type Attribute Description
    chunk any

    cb function Optional

    Returns void

  • Parameters

    Name Type Attribute Description
    chunk any

    encoding string Optional

    cb function Optional

    Returns void

eventNames

  • eventNames(): Array<string | symbol>

finish

  • finish(): void

getMaxListeners

  • getMaxListeners(): number

getTransactionId

  • getTransactionId(): Promise<string>
  • Returns a Promise that resolves with Watson Transaction ID from the X-Transaction-ID header

    Works in Node.js but not in browsers (the W3C WebSocket API does not expose headers)

    Returns Promise<string>

    Promise

initialize

  • initialize(): void

isPaused

  • isPaused(): boolean

listenerCount

  • listenerCount(type: string | symbol): number

listeners

  • listeners(event: string | symbol): Function[]

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    Name Type Attribute Description
    event string | symbol

    listener function

    Returns this

on

  • on(event: "close", listener: function): this
  • on(event: "data", listener: function): this
  • on(event: "end", listener: function): this
  • on(event: "error", listener: function): this
  • on(event: "pause", listener: function): this
  • on(event: "readable", listener: function): this
  • on(event: "resume", listener: function): this
  • on(event: string | symbol, listener: function): this
  • Parameters

    Name Type Attribute Description
    event "close"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "data"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "end"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "error"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "pause"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "readable"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "resume"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event string | symbol

    listener function

    Returns this

once

  • once(event: "close", listener: function): this
  • once(event: "data", listener: function): this
  • once(event: "end", listener: function): this
  • once(event: "error", listener: function): this
  • once(event: "pause", listener: function): this
  • once(event: "readable", listener: function): this
  • once(event: "resume", listener: function): this
  • once(event: string | symbol, listener: function): this
  • Parameters

    Name Type Attribute Description
    event "close"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "data"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "end"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "error"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "pause"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "readable"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "resume"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event string | symbol

    listener function

    Returns this

pause

  • pause(): this

pipe

  • pipe<T>(destination: T, options?: object): T
  • Type parameters

    • T: WritableStream

    Parameters

    Name Type Attribute Description
    destination T

    options object Optional

    Returns T

prependListener

  • prependListener(event: "close", listener: function): this
  • prependListener(event: "data", listener: function): this
  • prependListener(event: "end", listener: function): this
  • prependListener(event: "error", listener: function): this
  • prependListener(event: "pause", listener: function): this
  • prependListener(event: "readable", listener: function): this
  • prependListener(event: "resume", listener: function): this
  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    Name Type Attribute Description
    event "close"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "data"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "end"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "error"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "pause"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "readable"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "resume"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event string | symbol

    listener function

    Returns this

prependOnceListener

  • prependOnceListener(event: "close", listener: function): this
  • prependOnceListener(event: "data", listener: function): this
  • prependOnceListener(event: "end", listener: function): this
  • prependOnceListener(event: "error", listener: function): this
  • prependOnceListener(event: "pause", listener: function): this
  • prependOnceListener(event: "readable", listener: function): this
  • prependOnceListener(event: "resume", listener: function): this
  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    Name Type Attribute Description
    event "close"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "data"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "end"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "error"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "pause"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "readable"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "resume"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event string | symbol

    listener function

    Returns this

push

  • push(chunk: any, encoding?: string): boolean
  • Parameters

    Name Type Attribute Description
    chunk any

    encoding string Optional

    Returns boolean

rawListeners

  • rawListeners(event: string | symbol): Function[]

read

  • read(size?: number): any
  • Parameters

    Name Type Attribute Description
    size number Optional

    Returns any

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeListener

  • removeListener(event: "close", listener: function): this
  • removeListener(event: "data", listener: function): this
  • removeListener(event: "end", listener: function): this
  • removeListener(event: "error", listener: function): this
  • removeListener(event: "pause", listener: function): this
  • removeListener(event: "readable", listener: function): this
  • removeListener(event: "resume", listener: function): this
  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    Name Type Attribute Description
    event "close"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "data"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "end"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "error"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "pause"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "readable"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event "resume"

    listener function

    Returns this

  • Parameters

    Name Type Attribute Description
    event string | symbol

    listener function

    Returns this

resume

  • resume(): this

sendData

  • sendData(data: any): void

sendJSON

  • sendJSON(msg: any): void

setDefaultEncoding

  • setDefaultEncoding(encoding: string): this

setEncoding

  • setEncoding(encoding: string): this

setMaxListeners

  • setMaxListeners(n: number): this

stop

  • stop(): void
  • 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.

    Returns void

uncork

  • uncork(): void

unpipe

  • unpipe(destination?: WritableStream): this
  • Parameters

    Name Type Attribute Description
    destination WritableStream Optional

    Returns this

unshift

  • unshift(chunk: any, encoding?: BufferEncoding): void
  • Parameters

    Name Type Attribute Description
    chunk any

    encoding BufferEncoding Optional

    Returns void

wrap

  • wrap(oldStream: ReadableStream): this
  • Parameters

    Name Type Attribute Description
    oldStream ReadableStream

    Returns this

write

  • write(chunk: any, encoding?: string, cb?: function): boolean
  • write(chunk: any, cb?: function): boolean
  • Parameters

    Name Type Attribute Description
    chunk any

    encoding string Optional

    cb function Optional

    Returns boolean

  • Parameters

    Name Type Attribute Description
    chunk any

    cb function Optional

    Returns boolean

Static from

  • from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable
  • A utility method for creating Readable Streams out of iterators.

    Parameters

    Name Type Attribute Description
    iterable Iterable<any> | AsyncIterable<any>

    options ReadableOptions Optional

    Returns Readable

Static getContentType

  • getContentType(buffer: Buffer): string

Generated using TypeDoc