Skip to main content
Version: Next

Interface: TextToSpeechType

Defined in: types/tts.ts:99

Return type for the useTextToSpeech hook. Manages the state and operations for Text-to-Speech generation.

Properties

downloadProgress

downloadProgress: number

Defined in: types/tts.ts:118

Represents the download progress of the model and voice assets as a value between 0 and 1.


error

error: RnExecutorchError | null

Defined in: types/tts.ts:103

Contains the error object if the model failed to load or encountered an error during inference.


forward()

forward: (input) => Promise<Float32Array<ArrayBufferLike>>

Defined in: types/tts.ts:126

Runs the model to convert the provided text into speech audio in a single pass.

Parameters

input

TextToSpeechInput

The TextToSpeechInput object containing the text to synthesize and optional speed.

Returns

Promise<Float32Array<ArrayBufferLike>>

A Promise that resolves with the generated audio data (typically a Float32Array).

Throws

If the model is not loaded or is currently generating.


isGenerating

isGenerating: boolean

Defined in: types/tts.ts:113

Indicates whether the model is currently generating audio.


isReady

isReady: boolean

Defined in: types/tts.ts:108

Indicates whether the Text-to-Speech model is loaded and ready to accept inputs.


stream()

stream: (input) => Promise<void>

Defined in: types/tts.ts:135

Streams the generated audio data incrementally. This is optimal for real-time playback, allowing audio to start playing before the full text is synthesized.

Parameters

input

TextToSpeechStreamingInput

The TextToSpeechStreamingInput object containing text, optional speed, and lifecycle callbacks (onBegin, onNext, onEnd).

Returns

Promise<void>

A Promise that resolves when the streaming process is complete.

Throws

If the model is not loaded or is currently generating.


streamFlush()

streamFlush: () => void

Defined in: types/tts.ts:158

Requests the streaming session to partition and synthesize whatever is currently buffered, even if no end-of-sentence character is present.

Call after the final streamInsert of an utterance when you want trailing un-terminated content to play out without ending the stream. LLM-style callers feeding partial tokens typically should not call this — model punctuation drives natural EOS partitioning, and the residual tail is drained by streamStop(false) when generation completes.

Returns

void


streamInsert()

streamInsert: (textChunk) => void

Defined in: types/tts.ts:146

Inserts a new text chunk into the buffer to be processed in streaming mode.

Chunks accumulate until an end-of-sentence character (.?!;…) appears in the buffer, at which point they're partitioned and synthesized. If the caller stops feeding before an EOS arrives, the trailing tail will sit in the buffer until streamFlush() or streamStop(false) is called.

Parameters

textChunk

string

Text (or IPA phonemes) to append to the streaming buffer.

Returns

void


streamStop()

streamStop: (instant?) => void

Defined in: types/tts.ts:169

Interrupts and stops the currently active audio generation stream.

Parameters

instant?

boolean

If true, stops the streaming as soon as possible. Otherwise drains the current buffer (force-flushing any trailing un-terminated content) before stopping — equivalent to calling TextToSpeechType.streamFlush followed by an automatic stop once the buffer empties, so this call always returns.

Returns

void