/** * transformers.js (ONNX, dual-environment) TTS (text-to-speech) adapter battery. * * @module @nhtio/adk/batteries/tts/transformers_js/adapter * * @remarks * Battery backed by transformers.js's `text-to-speech` (TextToAudio) pipeline. **Environment-neutral** * — runs in Node (via `onnxruntime-node`) and the browser (via `onnxruntime-web` / WebGPU), auto-selected * by the package; there is no WebGPU requirement, mirroring the transformers.js STT and Embeddings * batteries this adapter is modeled on. * * Accepts plain text input, resolves speaker embeddings / speed / inference steps from the merged * constructor + per-call options, and returns a WAV-encoded {@link GeneratedMediaOutput}. * * `@huggingface/transformers` is an optional peer dependency, imported lazily. */ import type { GeneratedMediaOutput } from "../_shared/index"; import type { TransformersJsSynthesizeOptions } from "./types"; /** * TTS adapter for transformers.js's text-to-speech (TextToAudio) pipeline. * * @remarks * Reusable: construct once, call {@link TransformersJsTtsAdapter.synthesize} as many times as needed. * The pipeline is resolved lazily on first use (or via {@link preload}) and cached with single-flight * semantics so concurrent calls share one load. */ export declare class TransformersJsTtsAdapter { #private; /** * 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. */ static isAvailable(): boolean; /** * @param options - Constructor options. Validated eagerly. * @throws {@link @nhtio/adk/batteries!E_INVALID_TRANSFORMERS_JS_TTS_OPTIONS} when invalid. */ constructor(options: unknown); /** Instance availability probe (honours an injected `isAvailable`). */ isAvailable(): boolean; /** Eagerly loads (and caches) the pipeline so the first `synthesize` call is fast. Idempotent. */ preload(): Promise; /** Drops the cached pipeline and in-flight load so the next call reloads. */ reset(): void; /** * Release the loaded model's ONNX sessions + GPU/wasm buffers, then drop the cached pipeline. * * @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. */ dispose(): Promise; /** * Synthesizes text into a WAV audio clip. * * @param text - The text to speak. Passed verbatim to the pipeline. * @param opts - Per-call options; each field overrides the constructor default of the same name. * @returns A {@link GeneratedMediaOutput} descriptor with `kind: 'audio'`, `mimeType: 'audio/wav'`, * and the WAV bytes. * @throws {@link @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()`. */ synthesize(text: string, opts?: TransformersJsSynthesizeOptions): Promise; }