TextToSpeech class

Performs text-to-speech synthesis.

Signature:

export declare class TextToSpeech extends TaskRunner 

Extends: TaskRunner

Methods

Method Modifiers Description
cancel() Cancels any in-progress synthesis or streaming session.
close() Releases all native WASM resources held by this TextToSpeech instance.
createFromModelBuffer(wasmFileset, modelAssetBuffer) static Initializes the Wasm runtime and creates a new TextToSpeech instance based on the provided model asset buffer.
createFromModelPath(wasmFileset, modelAssetPath) static Initializes the Wasm runtime and creates a new TextToSpeech instance based on the path to the model asset.
createFromOptions(wasmFileset, options) static Initializes the Wasm runtime and creates a new TextToSpeech instance from the provided options.
listVoices() Lists all voices bundled in the loaded TTS model.
setOptions(options) Sets new options for the TextToSpeech instance.
synthesize(text, options) Synthesizes speech for the given text and returns the complete PCM waveform.
synthesizeStream(initialText, options, finishInput) Starts an incremental streaming synthesis session and returns a TtsStream (TextToSpeechStream) that yields audio chunks as they are generated.

TextToSpeech.cancel()

Cancels any in-progress synthesis or streaming session.

Signature:

cancel(): void;

Returns:

void

TextToSpeech.close()

Releases all native WASM resources held by this TextToSpeech instance.

Signature:

close(): void;

Returns:

void

TextToSpeech.createFromModelBuffer()

Initializes the Wasm runtime and creates a new TextToSpeech instance based on the provided model asset buffer.

Signature:

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

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetBuffer Uint8Array | ReadableStreamDefaultReader A binary representation of the model or a stream reader.

Returns:

Promise<TextToSpeech>

TextToSpeech.createFromModelPath()

Initializes the Wasm runtime and creates a new TextToSpeech instance based on the path to the model asset.

Signature:

static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: TrustedResourceUrl | string): Promise<TextToSpeech>;

Parameters

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

Returns:

Promise<TextToSpeech>

TextToSpeech.createFromOptions()

Initializes the Wasm runtime and creates a new TextToSpeech instance from the provided options.

Signature:

static createFromOptions(wasmFileset: WasmFileset, options: TextToSpeechOptions): Promise<TextToSpeech>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
options TextToSpeechOptions The options for the TextToSpeech task.

Returns:

Promise<TextToSpeech>

TextToSpeech.listVoices()

Lists all voices bundled in the loaded TTS model.

Signature:

listVoices(): Promise<VoiceInfo[]>;

Returns:

Promise<VoiceInfo[]>

TextToSpeech.setOptions()

Sets new options for the TextToSpeech instance.

Signature:

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

Parameters

Parameter Type Description
options TextToSpeechOptions New options to apply.

Returns:

Promise<void>

TextToSpeech.synthesize()

Synthesizes speech for the given text and returns the complete PCM waveform.

Signature:

synthesize(text: string, options?: SynthesisOptions): Promise<TtsAudioResult>;

Parameters

Parameter Type Description
text string Input text to synthesize.
options SynthesisOptions Optional per-call voice and locale overrides.

Returns:

Promise<TtsAudioResult>

TextToSpeech.synthesizeStream()

Starts an incremental streaming synthesis session and returns a TtsStream (TextToSpeechStream) that yields audio chunks as they are generated.

Signature:

synthesizeStream(initialText?: string, options?: SynthesisOptions, finishInput?: boolean): Promise<TtsStream>;

Parameters

Parameter Type Description
initialText string Optional initial text to begin synthesizing immediately.
options SynthesisOptions Optional per-call voice and locale overrides.
finishInput boolean Whether initialText is the complete input (defaults to true when initialText is provided, false when omitted).

Returns:

Promise<TtsStream>