Skip to main content
Version: Next

Class: TextToSpeechModule

Defined in: modules/natural_language_processing/TextToSpeechModule.ts:17

Module for Text to Speech (TTS) functionalities.

Methods

delete()

delete(): void

Defined in: modules/natural_language_processing/TextToSpeechModule.ts:314

Unloads the model from memory.

Returns

void


forward()

forward(input, speed?, phonemize?, totalSteps?, lang?): Promise<Float32Array<ArrayBufferLike>>

Defined in: modules/natural_language_processing/TextToSpeechModule.ts:178

Synthesizes the provided input into speech.

Parameters

input

string

The input text (or IPA phonemes for kokoro) to be synthesized.

speed?

number = 1.0

Playback speed multiplier (default: 1.0).

phonemize?

boolean = true

kokoro only: if true (default) treats input as text and converts it to phonemes; if false input is IPA phonemes.

totalSteps?

number = 8

supertonic only: number of flow-matching steps (default 8).

lang?

string = ''

Language override (defaults to model config).

Returns

Promise<Float32Array<ArrayBufferLike>>

A generated speech waveform.


stream()

stream(input): AsyncGenerator<Float32Array<ArrayBufferLike>>

Defined in: modules/natural_language_processing/TextToSpeechModule.ts:205

Starts a streaming synthesis session. Yields audio chunks as they are generated.

Parameters

input

TextToSpeechStreamingInput

Input object containing optional speed, phonemize / totalSteps and stopAutomatically flag.

Returns

AsyncGenerator<Float32Array<ArrayBufferLike>>

An async generator yielding Float32Array audio chunks.

Yields

An audio chunk generated during synthesis.


streamFlush()

streamFlush(): void

Defined in: modules/natural_language_processing/TextToSpeechModule.ts:293

Force-partitions whatever is currently buffered, even without an end-of-sentence character. Call after the final streamInsert of an utterance to play out the trailing tail without ending the stream.

Returns

void


streamInsert()

streamInsert(input): void

Defined in: modules/natural_language_processing/TextToSpeechModule.ts:282

Inserts new content (text or IPA phonemes) into the buffer to be processed in streaming mode. Trailing un-terminated content sits in the buffer until TextToSpeechModule.streamFlush or streamStop(false) releases it.

Parameters

input

string

The text or phoneme fragment to append to the streaming buffer.

Returns

void


streamStop()

streamStop(instant?): void

Defined in: modules/natural_language_processing/TextToSpeechModule.ts:303

Stops the streaming process if there is any ongoing.

Parameters

instant?

boolean = true

If true, stops the streaming as soon as possible. Otherwise drains the current buffer (force-flushing any trailing un-terminated content) before stopping.

Returns

void


fromModelName()

static fromModelName(config, onDownloadProgress?): Promise<TextToSpeechModule>

Defined in: modules/natural_language_processing/TextToSpeechModule.ts:33

Creates a Text to Speech instance.

Parameters

config

TextToSpeechModelConfig

Configuration object containing model and voice sources.

onDownloadProgress?

(progress) => void

Optional callback to monitor download progress, receiving a value between 0 and 1.

Returns

Promise<TextToSpeechModule>

A Promise resolving to a TextToSpeechModule instance.