import type { SpeechPlayback } from "./audio/speech-playback.js"; import { SynthesisCache } from "./audio/synthesis-cache.js"; import { SynthesizedAudio } from "./audio/synthesized-audio.js"; import type { DevicePreference, ResolvedDevice } from "./device.js"; import type { SynthesisEngine } from "./engine/types.js"; import type { PcmAudio, Platform } from "./platform.js"; import type { VoiceEmbedding, VoiceStore } from "./voice/types.js"; /** Anything that can be turned into reference audio. */ export type VoiceSource = ArrayBuffer | ArrayBufferView | Blob | PcmAudio; export interface VoxShotOptions { /** * Which backend to run inference on. * * @defaultValue "auto" */ device?: DevicePreference; /** * Model identifier. Only `"default"` exists today. * * @defaultValue "default" */ model?: string; /** Replace the synthesis engine, e.g. with an ONNX Runtime Web backend. */ engine?: SynthesisEngine; /** Replace voice persistence. Defaults to IndexedDB, or memory without it. */ voiceStore?: VoiceStore; /** Replace the browser bindings. Mostly useful for tests and non browser hosts. */ platform?: Platform; /** * Longest chunk, in characters, handed to the engine at once. * * @defaultValue 120 */ maxChunkLength?: number; /** * Shortest chunk, in characters. Shorter chunks are merged with their * neighbours, because very short prompts make neural TTS models unstable. * `0` disables merging. * * @defaultValue 0 */ minChunkLength?: number; /** Clock used for embedding timestamps. Injectable for deterministic tests. */ now?: () => number; /** * Cache of rendered audio, keyed by voice, text and speed. Pass your own * to tune its size, or `null` to disable caching entirely. * * @defaultValue a `SynthesisCache` with its default capacity */ synthesisCache?: SynthesisCache | null; } export interface SpeakOptions { /** * Playback rate multiplier passed to the engine. * * @defaultValue 1 */ speed?: number; /** * How expressive this utterance should be, overriding the engine's default * for this call only. * * Named for the effect rather than for any one model's parameter, so it can * mean something across engines — `ChatterboxEngine` maps it onto its * `exaggeration` control, and an engine without such a control ignores it. * Omit it to leave the engine's own default in place. */ expressiveness?: number; /** * Stops the utterance when it aborts. * * A long text is many renders, not one: a paper-sized input is hundreds of * chunks and can occupy the engine for the better part of an hour. Dropping * the promise does not stop any of that — and since the engine runs one call * at a time, abandoned work blocks everything queued behind it. * * {@link stream} and {@link speak} stop at the next chunk boundary and hand * the signal to the engine, so an engine that can interrupt a render in * flight does. {@link play} stops playback, exactly as calling `stop()` on * its handle would. */ signal?: AbortSignal; } export interface PlayOptions extends SpeakOptions { /** * Initial playback gain, non negative. * * @defaultValue 1 */ volume?: number; } /** * The VoxShot facade: clone a voice, then speak with it. * * ```ts * const tts = await VoxShot.create(); * await tts.cloneVoice(referenceAudioFile); * const audio = await tts.speak("Hello!"); * await audio.play(); * ``` */ export declare class VoxShot { #private; private constructor(); /** Resolve the device, load the engine and return a ready instance. */ static create(options?: VoxShotOptions): Promise; /** The backend inference actually runs on. */ get device(): ResolvedDevice; /** Sample rate of the audio this instance produces. */ get sampleRate(): number; /** The voice currently used for synthesis, if any. */ get currentVoice(): VoiceEmbedding | undefined; /** * Extract a voice from reference audio and make it the active voice. * * Accepts an encoded file (`ArrayBuffer`, `Blob`, `File`, typed array) or * ready made mono PCM. */ cloneVoice(source: VoiceSource): Promise; /** Synthesize the whole text and return it as one audio result. */ speak(text: string, options?: SpeakOptions): Promise; /** * Synthesize the text chunk by chunk, yielding each as soon as it is ready, * so playback can start before the whole utterance is rendered. */ stream(text: string, options?: SpeakOptions): AsyncGenerator; /** * Speak through the platform's gapless streaming output. * * Unlike {@link speak}, playback starts as soon as the first chunk is * rendered, the next chunk is synthesized while the current one plays, and * the returned handle can stop, skip and change volume mid-utterance. */ play(text: string, options?: PlayOptions): SpeechPlayback; /** Persist the active voice under `name`. */ saveVoice(name: string): Promise; /** Load a persisted voice and make it active. */ useVoice(name: string): Promise; /** * Remove a persisted voice. The active voice stays loaded even when it is * the one being deleted, so synthesis in flight keeps working. */ deleteVoice(name: string): Promise; /** Every persisted voice name. */ listVoices(): Promise; /** Release the engine. The instance is unusable afterwards. */ dispose(): Promise; } //# sourceMappingURL=voxshot.d.ts.map