> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inworld.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Text-to-Speech (TTS) Primitive Demo

The Text-to-Speech (TTS) template shows how to make a simple TTS call using the TTS primitive.

<Note>
  The TTS primitive module uses the legacy TTS system.

  This module supports both remote and local models.

  However, newer versions of Inworld TTS can only be used remotely and as a Node in the Graph system.
</Note>

## Run the Template

1. Go to `Assets/InworldRuntime/Scenes/Primitives` and play the `TTSTemplate` scene.
   <img src="https://mintcdn.com/inworldai/pDD5vvrZThONehMe/img/unity/framework/TTS01.png?fit=max&auto=format&n=pDD5vvrZThONehMe&q=85&s=f93dffa2d53b71ce7a3783b8a8c8895a" alt="TTS01" width="855" height="531" data-path="img/unity/framework/TTS01.png" />
2. Toggle between `Remote` and `Local`, then press `Connect`.
3. Once connected, select a voice ID, then press `Preview` to listen.
4. You can also type any text and press `SEND` to generate the TTS result.

<iframe style={{ aspectRatio: '16 / 9', width: '100%', height: 'auto' }} src="https://drive.google.com/file/d//1hF4AGBaahjbxjcG_dqtXW_v-ZqVVBP9g/preview" title="Unity AI Runtime - Demo Video" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen />

## Understanding the Template

### Structure

* This demo has a single prefab under `InworldController`: `TTS`, which contains `InworldTTSModule`.
* When `InworldController` initializes, it calls `InitializeAsync()` on the TTS module (see [Primitives Overview](./overview)).
* It creates a `TTSFactory`, which then creates a `TTSInterface` or `VADInterface` based on `TTSConfig`.

### Workflow

At runtime, when `InworldController` invokes `OnFrameworkInitialized`, the demo's `TTSConfigPanel` in `TTSCanvas` listens for this event and enables the previously disabled UI.

When the user switches the voice ID, the system terminates the current `TTSInterface` and creates a new one with the updated voice ID.

When the user clicks the `Preview` button, the `TTSConfigPanel` calls `InworldController.TTS.TextToSpeechAsync()` with "Hello" as the parameter.

When the user presses Enter or clicks `Send`, `TTSConfigPanel` calls `InworldController.TTS.TextToSpeechAsync()` with the input text.

### VoiceID

The voice ID identifies which voice is speaking. You can find the full list on the character page in `Character Studio`.

<Note>
  The primitive TTS module uses our legacy model. Voice IDs may differ from those in the `TTS Playground`.

  To find available voices, open `Character Studio`, go to the character editing page, and select voices there.
</Note>

<img src="https://mintcdn.com/inworldai/pDD5vvrZThONehMe/img/unity/framework/TTS02.png?fit=max&auto=format&n=pDD5vvrZThONehMe&q=85&s=8f225818f3ecf62071dbb97f52e20820" alt="TTS02" width="2550" height="786" data-path="img/unity/framework/TTS02.png" />

<img src="https://mintcdn.com/inworldai/pDD5vvrZThONehMe/img/unity/framework/TTS03.png?fit=max&auto=format&n=pDD5vvrZThONehMe&q=85&s=03ef628e3d1a0181caeedbccac781113" alt="TTS03" width="1410" height="1254" data-path="img/unity/framework/TTS03.png" />

The `TTSInterface` in the current Inworld Agent Runtime DLL does not support changing voice IDs at runtime.

Therefore, changing the voice ID terminates the current `TTSInterface` and creates a new interface with the selected voice ID.
