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

# Soniox Text-to-Speech

> SonioxTTSService streams text incrementally to Soniox's WebSocket TTS endpoint for real-time speech synthesis.

## Overview

Soniox provides real-time text-to-speech synthesis using a WebSocket-based streaming API. `SonioxTTSService` streams text incrementally to the Soniox TTS endpoint and receives audio back as base64-encoded chunks. Multiple concurrent streams (up to 5) are multiplexed over a single WebSocket connection, making it efficient for interactive voice applications.

> [card] [Soniox TTS API Reference](https://reference-server.pipecat.ai/en/latest/api/pipecat.services.soniox.tts.html)
>
> Pipecat's API methods for Soniox TTS integration

> [card] [Example Implementation](https://github.com/pipecat-ai/pipecat/blob/main/examples/voice/voice-soniox.py)
>
> Complete example with Soniox STT and TTS

> [card] [Soniox Documentation](https://soniox.com/docs/api-reference/tts/websocket-api)
>
> Official Soniox TTS WebSocket API documentation

> [card] [Supported Languages](https://soniox.com/docs/tts/concepts/languages)
>
> Browse supported languages (60+)

## Installation

To use Soniox TTS, install the required dependencies:

```bash theme={null}
uv add "pipecat-ai[soniox]"
```

## Prerequisites

### Soniox Account Setup

Before using Soniox TTS, you need:

1. **Soniox Account**: Sign up at [Soniox Console](https://console.soniox.com)
2. **API Key**: Generate an API key from your console dashboard
3. **Voice Selection**: Choose from available voices

### Required Environment Variables

* `SONIOX_API_KEY`: Your Soniox API key for authentication

## Configuration

**api\_key** `str` *required*

Soniox API key for authentication. Create API keys at [Soniox
Console](https://console.soniox.com).

**url** `str` (default: wss\://tts-rt.soniox.com/tts-websocket)

WebSocket endpoint URL for Soniox TTS.

**sample\_rate** `int` (default: None)

Output sample rate in Hz. Must be one of `{8000, 16000, 24000, 44100, 48000}`
when using a raw PCM audio format. When `None`, inherits from the pipeline's
configured sample rate.

**audio\_format** `str` (default: pcm\_s16le)

Output audio format. Defaults to `"pcm_s16le"`, which matches Pipecat's
downstream audio pipeline.

**text\_aggregation\_mode** `TextAggregationMode` (default: None)

Controls how incoming text is aggregated before synthesis. `SENTENCE` (used
when `None`) buffers text until sentence boundaries, producing more natural
speech. `TOKEN` streams tokens directly for lower latency. Import from
`pipecat.services.tts_service`.

**settings** `SonioxTTSService.Settings` (default: None)

Runtime-configurable settings. See [Settings](#settings) below.

### Settings

Runtime-configurable settings passed via the `settings` constructor argument using `SonioxTTSService.Settings(...)`. These can be updated mid-conversation with `TTSUpdateSettingsFrame`. See [Service Settings](https://docs.pipecat.ai/pipecat/fundamentals/service-settings.md) for details.

| Parameter | Type | Default | Description |
| - | - | - | - |
| `model` | `str` | `tts-rt-v2` | TTS model identifier. *(Inherited from base settings.)* |
| `voice` | `str` | `Bryce` | Voice name (e.g. `"Bryce"`) or the UUID of a cloned voice in the project owning the API key. *(Inherited from base settings.)* |
| `language` | `Language \| str` | `Language.EN` | Language for synthesis. *(Inherited from base settings.)* See [supported languages](https://soniox.com/docs/tts/concepts/languages). |
| `speed` | `float \| None` | `None` | Speech rate multiplier in the range 0.7-1.3. `None` uses the Soniox server default (1.0). Changing this flushes the current context and starts a new stream with the updated value. |
| `reduce_silence` | `bool \| None` | `None` | Shorten the pauses between words so the speech flows more tightly, without changing how fast the words themselves are spoken. Only models whose catalogue entry reports `supports_silence_reduction` accept it. `None` uses the Soniox server default (false). |
| `client_reference_id` | `str \| None` | `None` | Client-defined identifier recorded with each request in the Soniox usage logs, for attributing usage to a customer or session. Ignored for temporary API keys. |

## Usage

### Basic Setup

```python theme={null}
import os
from pipecat.services.soniox.tts import SonioxTTSService

tts = SonioxTTSService(
    api_key=os.getenv("SONIOX_API_KEY"),
    settings=SonioxTTSService.Settings(
        voice="Maya",
    ),
)
```

### With Custom Voice and Model

```python theme={null}
tts = SonioxTTSService(
    api_key=os.getenv("SONIOX_API_KEY"),
    settings=SonioxTTSService.Settings(
        model="tts-rt-v2",
        voice="Bryce",
        language="en",
    ),
)
```

### With Speech Rate Control

```python theme={null}
tts = SonioxTTSService(
    api_key=os.getenv("SONIOX_API_KEY"),
    settings=SonioxTTSService.Settings(
        voice="Maya",
        speed=1.2,  # 20% faster speech (range: 0.7-1.3)
    ),
)
```

### With Cloned Voice

```python theme={null}
# Use a cloned voice by passing its UUID
tts = SonioxTTSService(
    api_key=os.getenv("SONIOX_API_KEY"),
    settings=SonioxTTSService.Settings(
        voice="a1b2c3d4-e5f6-7890-abcd-ef1234567890",  # UUID of cloned voice
    ),
)
```

### With Custom Sample Rate

```python theme={null}
tts = SonioxTTSService(
    api_key=os.getenv("SONIOX_API_KEY"),
    sample_rate=16000,
    settings=SonioxTTSService.Settings(
        voice="Maya",
    ),
)
```

## Notes

* **WebSocket streaming**: Soniox uses a persistent WebSocket connection for streaming text-in and audio-out, enabling low-latency real-time synthesis.
* **Concurrent streams**: The service supports up to 5 concurrent streams multiplexed over a single WebSocket connection via Pipecat's audio-context mechanism.
* **Keepalive**: The service automatically sends keepalive messages every 20 seconds to prevent Soniox's idle timeout (20-30s).
* **Language support**: Soniox supports 60+ languages, including Icelandic, Sundanese, and Uzbek. See the [language documentation](https://soniox.com/docs/tts/concepts/languages) for the complete list.
* **Word-aligned text frames**: The service emits `TTSTextFrame`s aligned with word timestamps from Soniox, so the LLM context reflects only what was actually spoken at the moment of interruption. This ensures accurate conversation state when the user interrupts mid-sentence.

## Event Handlers

Soniox TTS supports the standard [service connection events](https://docs.pipecat.ai/api-reference/server/events/service-events.md):

| Event | Description |
| - | - |
| `on_connected` | Connected to Soniox WebSocket |
| `on_disconnected` | Disconnected from Soniox WebSocket |
| `on_connection_error` | WebSocket connection error occurred |

```python theme={null}
@tts.event_handler("on_connected")
async def on_connected(service):
    print("Connected to Soniox TTS")
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.