Skip to content
2 min read · 356 words

Class: TransformersJsTtsAdapter

Defined in: src/batteries/tts/transformers_js/adapter.ts:59

TTS adapter for transformers.js's text-to-speech (TextToAudio) pipeline.

Remarks

Reusable: construct once, call TransformersJsTtsAdapter.synthesize 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 TransformersJsTtsAdapter(options: unknown): TransformersJsTtsAdapter;

Defined in: src/batteries/tts/transformers_js/adapter.ts:76

Parameters

ParameterTypeDescription
optionsunknownConstructor options. Validated eagerly.

Returns

TransformersJsTtsAdapter

Throws

@nhtio/adk/batteries!E_INVALID_TRANSFORMERS_JS_TTS_OPTIONS when invalid.

Methods

dispose()

ts
dispose(): Promise<void>;

Defined in: src/batteries/tts/transformers_js/adapter.ts:106

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. TextToAudioPipeline 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/tts/transformers_js/adapter.ts:82

Instance availability probe (honours an injected isAvailable).

Returns

boolean


preload()

ts
preload(): Promise<void>;

Defined in: src/batteries/tts/transformers_js/adapter.ts:87

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

Returns

Promise<void>


reset()

ts
reset(): void;

Defined in: src/batteries/tts/transformers_js/adapter.ts:92

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

Returns

void


synthesize()

ts
synthesize(text: string, opts?: TransformersJsSynthesizeOptions): Promise<GeneratedMediaOutput>;

Defined in: src/batteries/tts/transformers_js/adapter.ts:180

Synthesizes text into a WAV audio clip.

Parameters

ParameterTypeDescription
textstringThe text to speak. Passed verbatim to the pipeline.
opts?TransformersJsSynthesizeOptionsPer-call options; each field overrides the constructor default of the same name.

Returns

Promise<GeneratedMediaOutput>

A GeneratedMediaOutput descriptor with kind: 'audio', mimeType: 'audio/wav', and the WAV bytes.

Throws

@nhtio/adk/batteries!E_TRANSFORMERS_JS_TTS_ENGINE_ERROR when the pipeline fails to load, the synthesis call throws, or the returned audio lacks toBlob().


isAvailable()

ts
static isAvailable(): boolean;

Defined in: src/batteries/tts/transformers_js/adapter.ts:68

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