Class: TimingStream

TimingStream

new TimingStream(optsopt)

Slows results down to no faster than real time.

Useful when running recognizeFile because the text can otherwise appear before the words are spoken

Parameters:
Name Type Attributes Description
opts Object <optional>
Properties
Name Type Attributes Default Description
emitAtt * <optional>
TimingStream.START

set to TimingStream.END to only emit text that has been completely spoken.

delay Number <optional>
0

Additional delay (in seconds) to apply before emitting words, useful for precise syncing to audio tracks. May be negative

Source:

Methods

checkForEnd()

Triggers the 'close' and 'end' events if both pre-conditions are true:

  • the previous stream must have already emitted it's 'end' event
  • there must be no next tick scheduled, indicating that there are no results buffered for later delivery
Source:

getCurrentResult(results, cutoff) → {Object|undefined}

Returns one of:

  • undefined if the next result is completely later than the current cutoff
  • a cropped clone of the next result if it's later than the current cutoff && in objectMode
  • the original next result object (removing it from the array) if it's completely earlier than the current cutoff (or we're in string mode with emitAt set to start)
Parameters:
Name Type Description
results Object
cutoff Number
Source:
Returns:
Type
Object | undefined

handleResult(result)

Creates a new result with all transcriptions formatted

Parameters:
Name Type Description
result Object
Source:

scheduleNextTick(cutoff)

Schedules next tick if possible. Requires previous stream to emit recognize objects (objectMode or readableObjectMode)

triggers the 'close' and 'end' events if the buffer is empty and no further results are expected

Parameters:
Name Type Description
cutoff Number
Source:

tick()

Tick emits any buffered words that have a timestamp before the current time, then calls scheduleNextTick()

Source: