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

# Text-to-speech (TTS)

> Synthesize speech from text using on-device TTS models running on the Qualcomm NPU.

The TTS service converts text to speech using on-device models running fully on the Qualcomm NPU. Audio is returned as raw PCM via HTTP chunked transfer encoding.

## Prerequisites

Ensure the Audio Analytics container is deployed and running. See [Running the Audio Analytics container](/ai-workflows/audio-analytics-overview) for setup instructions.

## Available models

Query the models endpoint to get the list of available TTS models and voices:

```bash theme={null}
curl http://localhost:8085/audio-analytics/v1/api/tts/models
```

The currently available models are:

| Model          | Language | Native sample rate |
| -------------- | -------- | ------------------ |
| `melo-tts-en`  | English  | 44100 Hz           |
| `melo-tts-es`  | Spanish  | 44100 Hz           |
| `melo-tts-zh`  | Chinese  | 44100 Hz           |
| `piper-tts-en` | English  | 22050 Hz           |
| `piper-tts-de` | German   | 22050 Hz           |
| `piper-tts-it` | Italian  | 22050 Hz           |

Use the `name` value from the response in your synthesis requests.

## Endpoints

| Method | Endpoint          | Description                          |
| ------ | ----------------- | ------------------------------------ |
| `GET`  | `/tts/models`     | List available TTS models and voices |
| `POST` | `/tts/synthesize` | Synthesize speech from text          |
| `POST` | `/tts/cancel`     | Cancel an in-progress synthesis      |
| `POST` | `/tts/close`      | Close the active TTS session         |

## Synthesize speech

```bash theme={null}
curl -X POST http://localhost:8085/audio-analytics/v1/api/tts/synthesize \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Hello, how are you today?",
    "model": "melo-tts-en",
    "language": "en",
    "voice": "default",
    "sample_rate": 44100
  }' \
  --output speech.pcm
```

**Parameters:**

* `text` (required): Text to synthesize
* `model` (required): TTS model name
* `language` (optional): Language code (`en`, `es`, `zh`, `de`, `it`)
* `voice` (optional): Voice name (default: `default`)
* `sample_rate` (optional): Output sample rate — `44100`, `22050`, or `16000` Hz. Audio is resampled if different from the model's native rate.
* `parameters.speaking_rate` (optional): Speaking speed multiplier, e.g. `"0.8"` for slower, `"1.5"` for faster.

**Response:** Raw PCM audio streamed via HTTP chunked transfer.

<Note>TTS returns raw PCM, not WAV. Convert it to WAV before playback.</Note>

## Speaking rate

Adjust the speaking speed if supported by the model, e.g. `"0.8"` for slower or `"1.5"` for faster:

```bash theme={null}
curl -X POST http://localhost:8085/audio-analytics/v1/api/tts/synthesize \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Hello, this is a speech rate test.",
    "model": "melo-tts-en",
    "language": "en",
    "sample_rate": 44100,
    "parameters": {"speaking_rate": "1.5"}
  }' \
  --output speech.pcm
```

## Cancel synthesis

Stop an in-progress synthesis:

```bash theme={null}
curl -X POST http://localhost:8085/audio-analytics/v1/api/tts/cancel
```

## Close

Release TTS resources when done synthesizing:

```bash theme={null}
curl -X POST http://localhost:8085/audio-analytics/v1/api/tts/close
```

## Python example

```python theme={null}
import requests

def synthesize(text, model="melo-tts-en", language="en", sample_rate=44100):
    url = "http://localhost:8085/audio-analytics/v1/api/tts/synthesize"
    response = requests.post(url, json={
        "text": text,
        "model": model,
        "language": language,
        "sample_rate": sample_rate
    }, timeout=30)
    response.raise_for_status()
    with open("speech.pcm", "wb") as f:
        f.write(response.content)
    print(f"Saved {len(response.content)} bytes to speech.pcm")

synthesize("Hello, how are you today?")
```

## Troubleshooting

**PCM won't play:** PCM is raw audio. Convert it to WAV before playback.

**Poor audio quality:** Try a higher sample rate (44100 Hz) or check for special characters in the input text.

## Next steps

<CardGroup cols={2}>
  <Card title="Speech recognition" icon="microphone" href="/ai-workflows/asr-container">
    Transcribe audio to text on-device
  </Card>

  <Card title="Language translation" icon="language" href="/ai-workflows/language-translation">
    Translate text between languages on-device
  </Card>
</CardGroup>
