AudioTranscriber class

MediaPipe Audio Task that performs automatic speech recognition (ASR) in unary and streaming modes via WASM SIMD or WebGPU.

Signature:

export declare class AudioTranscriber extends TaskRunner 

Extends: TaskRunner

Methods

Method Modifiers Description
close() Closes the AudioTranscriber and releases native engine and Wasm memory.
createFromModelBuffer(wasmFileset, modelAssetBuffer) static Initializes the Wasm runtime and creates a new AudioTranscriber from a model asset buffer or stream.
createFromModelPath(wasmFileset, modelAssetPath) static Initializes the Wasm runtime and creates a new AudioTranscriber from a model asset path.
createFromOptions(wasmFileset, options) static Initializes the Wasm runtime and creates a new AudioTranscriber based on the provided options.
finishStream() Flushes any remaining buffered audio and finalizes the current stream. Finalized transcription segments.
prewarm() Prewarms the underlying inference engine to reduce first-chunk latency.
setOptions(options) Sets the options for the AudioTranscriber and initializes the underlying engine. Options cannot be updated once the engine has been created.
transcribe(audioSamples, endOfStream) Transcribes mono PCM float audio samples in [-1.0, 1.0].
transcribeStream(audioSamples) Feeds a streaming chunk of mono PCM float audio samples (endOfStream = false) and returns any newly emitted interim or final segments.

AudioTranscriber.close()

Closes the AudioTranscriber and releases native engine and Wasm memory.

Signature:

close(): void;

Returns:

void

AudioTranscriber.createFromModelBuffer()

Initializes the Wasm runtime and creates a new AudioTranscriber from a model asset buffer or stream.

Signature:

static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<AudioTranscriber>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetBuffer Uint8Array | ReadableStreamDefaultReader A Uint8Array or ReadableStreamDefaultReader containing the .litertlm model bytes.

Returns:

Promise<AudioTranscriber>

AudioTranscriber.createFromModelPath()

Initializes the Wasm runtime and creates a new AudioTranscriber from a model asset path.

Signature:

static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string): Promise<AudioTranscriber>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetPath string The path or URL to the .litertlm model asset.

Returns:

Promise<AudioTranscriber>

AudioTranscriber.createFromOptions()

Initializes the Wasm runtime and creates a new AudioTranscriber based on the provided options.

Signature:

static createFromOptions(wasmFileset: WasmFileset, options: AudioTranscriberOptions): Promise<AudioTranscriber>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
options AudioTranscriberOptions The options for the AudioTranscriber. Note that either a path to the model or the model buffer itself must be provided via baseOptions.

Returns:

Promise<AudioTranscriber>

AudioTranscriber.finishStream()

Flushes any remaining buffered audio and finalizes the current stream.

Finalized transcription segments.

Signature:

finishStream(): Promise<AudioTranscriberResult>;

Returns:

Promise<AudioTranscriberResult>

AudioTranscriber.prewarm()

Prewarms the underlying inference engine to reduce first-chunk latency.

Signature:

prewarm(): Promise<void>;

Returns:

Promise<void>

AudioTranscriber.setOptions()

Sets the options for the AudioTranscriber and initializes the underlying engine. Options cannot be updated once the engine has been created.

Signature:

setOptions(options: AudioTranscriberOptions): Promise<void>;

Parameters

Parameter Type Description
options AudioTranscriberOptions The options for the AudioTranscriber.

Returns:

Promise<void>

AudioTranscriber.transcribe()

Transcribes mono PCM float audio samples in [-1.0, 1.0].

Signature:

transcribe(audioSamples: Float32Array | number[], endOfStream?: boolean): Promise<AudioTranscriberResult>;

Parameters

Parameter Type Description
audioSamples Float32Array | number[] Mono PCM float audio samples at sampleRateHz.
endOfStream boolean Whether this chunk marks the end of the audio stream. Defaults to true (unary single-utterance mode). The transcription result containing segments and concatenated text.

Returns:

Promise<AudioTranscriberResult>

AudioTranscriber.transcribeStream()

Feeds a streaming chunk of mono PCM float audio samples (endOfStream = false) and returns any newly emitted interim or final segments.

Signature:

transcribeStream(audioSamples: Float32Array | number[]): Promise<AudioTranscriberResult>;

Parameters

Parameter Type Description
audioSamples Float32Array | number[] Mono PCM float audio samples at sampleRateHz. Newly emitted segments from the streaming session.

Returns:

Promise<AudioTranscriberResult>