<br />

MediaPipe Audio Task that performs neural text-to-speech synthesis in unary and streaming modes via WASM SIMD or WebGPU.

**Signature:**

```typescript
export declare class TextToSpeech extends TaskRunner 
```

## Methods

| Method | Modifiers | Description |
|---|---|---|
| [createFromOptions(wasmFileset, options)](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechcreatefromoptions) | `static` | Initializes the Wasm runtime and creates a new `TextToSpeech` instance based on the provided options. |
| [createFromModelPath(wasmFileset, modelAssetPath)](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechcreatefrommodelpath) | `static` | Initializes the Wasm runtime and creates a new `TextToSpeech` instance from a model asset path. |
| [createFromModelBuffer(wasmFileset, modelAssetBuffer)](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechcreatefrommodelbuffer) | `static` | Initializes the Wasm runtime and creates a new `TextToSpeech` instance from a model asset buffer or stream. |
| [setOptions(options)](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechsetoptions) |   | Sets the options for `TextToSpeech` and initializes the underlying engine. Options cannot be updated once the engine has been created. |
| [listVoices()](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechlistvoices) |   | Queries available voices bundled in the initialized model. |
| [synthesize(text, options)](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechsynthesize) |   | Synthesizes a complete utterance and returns the full PCM audio buffer. |
| [synthesizeStream(initialText, options, finishInput)](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechsynthesizestream) |   | Starts a streaming synthesis session returning a `TextToSpeechStream` (supporting both `readNext()` and `for await (const chunk of stream)`). |
| [openStream(initialText, options, finishInput)](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechopenstream) |   | Opens an incremental streaming synthesis session returning a `TextToSpeechStream` with `finishInput` defaulting to `false` so callers can push LLM text deltas via `stream.pushText()` and finish with `stream.finishInput()`. |
| [cancel()](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechcancel) |   | Cancels any in-flight unary or streaming synthesis on this `TextToSpeech` instance. |
| [close()](https://developers.google.com/edge/api/mediapipe/js/tasks-audio.texttospeech.md.txt#texttospeechclose) |   | Closes the `TextToSpeech` instance and releases native engine and Wasm memory. |

## TextToSpeech.createFromOptions()

Initializes the Wasm runtime and creates a new `TextToSpeech` instance based on the provided options.

**Signature:**

```typescript
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 TextToSpeech. Note that either a path to the model or the model buffer itself must be provided via `baseOptions`. |

**Returns:**

Promise\<TextToSpeech\>

## TextToSpeech.createFromModelPath()

Initializes the Wasm runtime and creates a new `TextToSpeech` instance from a model asset path.

**Signature:**

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

### Parameters

| Parameter | Type | Description |
|---|---|---|
| wasmFileset | WasmFileset | A configuration object that provides the location of the Wasm binary and its loader. |
| modelAssetPath | string \| string | The path or URL to the `.litertlm` model asset. |

**Returns:**

Promise\<TextToSpeech\>

## TextToSpeech.createFromModelBuffer()

Initializes the Wasm runtime and creates a new `TextToSpeech` instance from a model asset buffer or stream.

**Signature:**

```typescript
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 `Uint8Array` or `ReadableStreamDefaultReader` containing the `.litertlm` model bytes. |

**Returns:**

Promise\<TextToSpeech\>

## TextToSpeech.setOptions()

Sets the options for `TextToSpeech` and initializes the underlying engine. Options cannot be updated once the engine has been created.

**Signature:**

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

### Parameters

| Parameter | Type | Description |
|---|---|---|
| options | TextToSpeechOptions | The options for TextToSpeech. |

**Returns:**

Promise\<void\>

## TextToSpeech.listVoices()

Queries available voices bundled in the initialized model.

**Signature:**

```typescript
listVoices(): Promise<VoiceInfo[]>;
```

**Returns:**

Promise\<VoiceInfo\[\]\>

## TextToSpeech.synthesize()

Synthesizes a complete utterance and returns the full PCM audio buffer.

**Signature:**

```typescript
synthesize(text: string, options?: SynthesisOptions): Promise<TextToSpeechResult>;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| text | string | The text to synthesize. |
| options | SynthesisOptions | Optional per-utterance voice or locale overrides. |

**Returns:**

Promise\<TextToSpeechResult\>

## TextToSpeech.synthesizeStream()

Starts a streaming synthesis session returning a `TextToSpeechStream` (supporting both `readNext()` and `for await (const chunk of stream)`).

**Signature:**

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

### Parameters

| Parameter | Type | Description |
|---|---|---|
| initialText | string | Initial text to synthesize (pass `""` when streaming incremental LLM text deltas via `stream.pushText()`). |
| options | SynthesisOptions | Optional per-utterance voice or locale overrides. |
| finishInput | boolean | Pass `true` (default) for single-utterance streaming, or `false` to keep the input stream open for `stream.pushText()` and `stream.finishInput()`. |

**Returns:**

Promise\<TextToSpeechStream\>

## TextToSpeech.openStream()

Opens an incremental streaming synthesis session returning a `TextToSpeechStream` with `finishInput` defaulting to `false` so callers can push LLM text deltas via `stream.pushText()` and finish with `stream.finishInput()`.

**Signature:**

```typescript
openStream(initialText?: string, options?: SynthesisOptions, finishInput?: boolean): Promise<TextToSpeechStream>;
```

### Parameters

| Parameter | Type | Description |
|---|---|---|
| initialText | string | Optional initial text fragment to enqueue immediately. |
| options | SynthesisOptions | Optional per-utterance voice or locale overrides. |
| finishInput | boolean | Pass `false` (default) to keep the input stream open for `stream.pushText()`, or `true` for a single-utterance stream. |

**Returns:**

Promise\<TextToSpeechStream\>

## TextToSpeech.cancel()

Cancels any in-flight unary or streaming synthesis on this `TextToSpeech` instance.

**Signature:**

```typescript
cancel(): void;
```

**Returns:**

void

## TextToSpeech.close()

Closes the `TextToSpeech` instance and releases native engine and Wasm memory.

**Signature:**

```typescript
close(): void;
```

**Returns:**

void