Skip to content
2 min read · 346 words

Class: TransformersJsSttAdapter

Defined in: src/batteries/specialists/stt/transformers_js/adapter.ts:76

STT adapter for transformers.js's automatic-speech-recognition (Whisper-family) pipeline.

Remarks

Reusable: construct once, call TransformersJsSttAdapter.transcribe as many times as needed. The pipeline is resolved lazily on first use (or via preload) and cached with single-flight semantics so concurrent calls share one load.

Constructors

Constructor

ts
new TransformersJsSttAdapter(options: unknown): TransformersJsSttAdapter;

Defined in: src/batteries/specialists/stt/transformers_js/adapter.ts:93

Parameters

ParameterTypeDescription
optionsunknownConstructor options. Validated eagerly.

Returns

TransformersJsSttAdapter

Throws

@nhtio/adk/batteries!E_INVALID_TRANSFORMERS_JS_STT_OPTIONS when invalid.

Methods

dispose()

ts
dispose(): Promise<void>;

Defined in: src/batteries/specialists/stt/transformers_js/adapter.ts:123

Release the loaded model's ONNX sessions + GPU/wasm buffers, then drop the cached pipeline.

Returns

Promise<void>

Remarks

reset() only nulls the JS reference; the native ONNX Runtime sessions and WebGPU/wasm device memory stay alive until GC. AutomaticSpeechRecognitionPipeline extends Pipeline, which exposes dispose() — this awaits it so the memory is reclaimed between loads, swallows a disposal error (teardown must not throw), and finishes with reset(). Idempotent.


isAvailable()

ts
isAvailable(): boolean;

Defined in: src/batteries/specialists/stt/transformers_js/adapter.ts:99

Instance availability probe (honours an injected isAvailable).

Returns

boolean


preload()

ts
preload(): Promise<void>;

Defined in: src/batteries/specialists/stt/transformers_js/adapter.ts:104

Eagerly loads (and caches) the pipeline so the first transcribe call is fast. Idempotent.

Returns

Promise<void>


reset()

ts
reset(): void;

Defined in: src/batteries/specialists/stt/transformers_js/adapter.ts:109

Drops the cached pipeline and in-flight load so the next call reloads.

Returns

void


transcribe()

ts
transcribe(input: SpecialistAudioInput, opts?: TranscribeOptions): Promise<TranscribeResult>;

Defined in: src/batteries/specialists/stt/transformers_js/adapter.ts:222

Transcribes an audio clip.

Parameters

ParameterTypeDescription
inputSpecialistAudioInputThe audio input, in any @nhtio/adk/batteries/specialists/_shared!SpecialistAudioInput form (pre-decoded PCM or an encoded container).
opts?TranscribeOptionsPer-call transcription options (language / translate / timestamps).

Returns

Promise<TranscribeResult>

The recognized text, plus per-segment timing when opts.timestamps was set.

Throws

@nhtio/adk/batteries!E_TRANSFORMERS_JS_STT_ENGINE_ERROR when the pipeline fails to load or the transcription call fails.


isAvailable()

ts
static isAvailable(): boolean;

Defined in: src/batteries/specialists/stt/transformers_js/adapter.ts:85

Whether this battery is available. transformers.js is environment-neutral (Node + browser), so this is true whenever the runtime can import the peer — there is no WebGPU requirement.

Returns

boolean