> ## Documentation Index
> Fetch the complete documentation index at: https://daily-main.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Sarvam AI Text-to-Speech

> TTS for Indian languages with SarvamTTSService and SarvamHttpTTSService, with extensive voice customization on Sarvam AI's API.

## Overview

`SarvamTTSService` provides text-to-speech synthesis specialized for Indian languages and voices. The service uses the `bulbul:v3` model by default, which offers temperature control for output randomness, pace adjustment, and 21 speaker voices. The previous `bulbul:v2` model is deprecated as Sarvam's API no longer serves it.

<CardGroup cols={2}>
  <Card title="Sarvam TTS API Reference" icon="code" href="https://reference-server.pipecat.ai/en/latest/api/pipecat.services.sarvam.tts.html">
    Pipecat's API methods for Sarvam AI TTS integration
  </Card>

  <Card title="Example Implementation" icon="play" href="https://github.com/pipecat-ai/pipecat/blob/main/examples/voice/voice-sarvam.py">
    Complete example with Indian language support
  </Card>

  <Card title="Sarvam Documentation" icon="book" href="https://docs.sarvam.ai/api-reference-docs/text-to-speech/convert">
    Official Sarvam AI text-to-speech API documentation
  </Card>

  <Card title="Sarvam Console" icon="microphone" href="https://www.sarvam.ai/">
    Access Indian language voices and API keys
  </Card>
</CardGroup>

## Installation

To use Sarvam AI services, no additional dependencies are required beyond the base installation:

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

## Prerequisites

### Sarvam AI Account Setup

Before using Sarvam AI TTS services, you need:

1. **Sarvam AI Account**: Sign up at [Sarvam AI Console](https://www.sarvam.ai/)
2. **API Key**: Generate an API key from your account dashboard
3. **Language Selection**: Choose from available Indian language voices

### Required Environment Variables

* `SARVAM_API_KEY`: Your Sarvam AI API key for authentication

## Configuration

Sarvam offers two service implementations: `SarvamTTSService` (WebSocket) for real-time streaming and `SarvamHttpTTSService` (HTTP) for simpler batch synthesis.

### SarvamTTSService

<ParamField path="api_key" type="str" required>
  Sarvam AI API subscription key.
</ParamField>

<ParamField path="model" type="str" default="bulbul:v3" deprecated>
  TTS model to use. Options: `bulbul:v3`, `bulbul:v3-beta`, `bulbul:v2`
  (deprecated). *Deprecated in v0.0.105. Use
  `settings=SarvamTTSService.Settings(model=...)` instead.*
</ParamField>

<ParamField path="voice_id" type="str" default="None" deprecated>
  Speaker voice ID. If `None`, uses `shubh` (the default for v3). *Deprecated in
  v0.0.105. Use `settings=SarvamTTSService.Settings(voice=...)` instead.*
</ParamField>

<ParamField path="url" type="str" default="wss://api.sarvam.ai/text-to-speech/ws">
  WebSocket URL for the TTS backend.
</ParamField>

<ParamField path="text_aggregation_mode" type="TextAggregationMode" default="TextAggregationMode.SENTENCE">
  Controls how incoming text is aggregated before synthesis. `SENTENCE`
  (default) buffers text until sentence boundaries, producing more natural
  speech. `TOKEN` streams tokens directly for lower latency. Import from
  `pipecat.services.tts_service`.
</ParamField>

<ParamField path="aggregate_sentences" type="bool" default="None" deprecated>
  *Deprecated in v0.0.104.* Use `text_aggregation_mode` instead.
</ParamField>

<ParamField path="sample_rate" type="int" default="None">
  Audio sample rate in Hz (8000, 16000, 22050, 24000, and for v3: 32000, 44100,
  48000\). If `None`, uses model-specific default (24000 for v3, 22050 for
  deprecated v2).
</ParamField>

<ParamField path="params" type="InputParams" default="None" deprecated>
  *Deprecated in v0.0.105. Use `settings=SarvamTTSService.Settings(...)`
  instead.*
</ParamField>

<ParamField path="settings" type="SarvamTTSService.Settings" default="None">
  Runtime-configurable settings. See [SarvamTTSService
  Settings](#sarvamttsservice-settings) below.
</ParamField>

### SarvamHttpTTSService

<ParamField path="api_key" type="str" required>
  Sarvam AI API subscription key.
</ParamField>

<ParamField path="aiohttp_session" type="aiohttp.ClientSession" required>
  An aiohttp session for HTTP requests.
</ParamField>

<ParamField path="model" type="str" default="bulbul:v3" deprecated>
  TTS model to use. Options: `bulbul:v3`, `bulbul:v3-beta`, `bulbul:v2`
  (deprecated). *Deprecated in v0.0.105. Use
  `settings=SarvamHttpTTSService.Settings(model=...)` instead.*
</ParamField>

<ParamField path="voice_id" type="str" default="None" deprecated>
  Speaker voice ID. If `None`, uses `shubh` (the default for v3). *Deprecated in
  v0.0.105. Use `settings=SarvamHttpTTSService.Settings(voice=...)` instead.*
</ParamField>

<ParamField path="base_url" type="str" default="https://api.sarvam.ai">
  Sarvam AI API base URL.
</ParamField>

<ParamField path="sample_rate" type="int" default="None">
  Audio sample rate in Hz (8000, 16000, 22050, 24000, and for v3: 32000, 44100,
  48000\). If `None`, uses model-specific default (24000 for v3, 22050 for
  deprecated v2).
</ParamField>

<ParamField path="params" type="InputParams" default="None" deprecated>
  *Deprecated in v0.0.105. Use `settings=SarvamHttpTTSService.Settings(...)`
  instead.*
</ParamField>

<ParamField path="settings" type="SarvamHttpTTSService.Settings" default="None">
  Runtime-configurable settings. See [SarvamHttpTTSService
  Settings](#sarvamhttpttsservice-settings) below.
</ParamField>

#### SarvamTTSService Settings

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

| Parameter              | Type              | Default     | Description                            |
| ---------------------- | ----------------- | ----------- | -------------------------------------- |
| `model`                | `str`             | `None`      | Model identifier. *(Inherited.)*       |
| `voice`                | `str`             | `None`      | Voice identifier. *(Inherited.)*       |
| `language`             | `Language \| str` | `None`      | Language for synthesis. *(Inherited.)* |
| `enable_preprocessing` | `bool`            | `NOT_GIVEN` | Enable text preprocessing.             |
| `pace`                 | `float`           | `NOT_GIVEN` | Pace of speech.                        |
| `pitch`                | `float`           | `NOT_GIVEN` | Pitch of speech.                       |
| `loudness`             | `float`           | `NOT_GIVEN` | Loudness of speech.                    |
| `temperature`          | `float`           | `NOT_GIVEN` | Temperature for speech synthesis.      |
| `min_buffer_size`      | `int`             | `NOT_GIVEN` | Minimum buffer size for WebSocket.     |
| `max_chunk_length`     | `int`             | `NOT_GIVEN` | Maximum chunk length for WebSocket.    |

#### SarvamHttpTTSService Settings

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

| Parameter              | Type              | Default     | Description                            |
| ---------------------- | ----------------- | ----------- | -------------------------------------- |
| `model`                | `str`             | `None`      | Model identifier. *(Inherited.)*       |
| `voice`                | `str`             | `None`      | Voice identifier. *(Inherited.)*       |
| `language`             | `Language \| str` | `None`      | Language for synthesis. *(Inherited.)* |
| `enable_preprocessing` | `bool`            | `NOT_GIVEN` | Enable text preprocessing.             |
| `pace`                 | `float`           | `NOT_GIVEN` | Pace of speech.                        |
| `pitch`                | `float`           | `NOT_GIVEN` | Pitch of speech.                       |
| `loudness`             | `float`           | `NOT_GIVEN` | Loudness of speech.                    |
| `temperature`          | `float`           | `NOT_GIVEN` | Temperature for speech synthesis.      |

## Usage

### Basic Setup (WebSocket)

```python theme={null}
from pipecat.services.sarvam.tts import SarvamTTSService
from pipecat.transcriptions.language import Language

tts = SarvamTTSService(
    api_key=os.getenv("SARVAM_API_KEY"),
    settings=SarvamTTSService.Settings(
        voice="shubh",
        model="bulbul:v3",
        language=Language.HI,
    ),
)
```

### With Temperature Control

```python theme={null}
from pipecat.services.sarvam.tts import SarvamTTSService
from pipecat.transcriptions.language import Language

tts = SarvamTTSService(
    api_key=os.getenv("SARVAM_API_KEY"),
    settings=SarvamTTSService.Settings(
        voice="shubh",
        model="bulbul:v3",
        language=Language.HI,
        pace=1.2,
        temperature=0.8,
    ),
)
```

### HTTP Service

```python theme={null}
import aiohttp
from pipecat.services.sarvam.tts import SarvamHttpTTSService
from pipecat.transcriptions.language import Language

async with aiohttp.ClientSession() as session:
    tts = SarvamHttpTTSService(
        api_key=os.getenv("SARVAM_API_KEY"),
        aiohttp_session=session,
        settings=SarvamHttpTTSService.Settings(
            voice="shubh",
            model="bulbul:v3",
            language=Language.HI,
            pace=1.2,
            temperature=0.8,
        ),
    )
```

<Tip>
  The `InputParams` / `params=` pattern is deprecated as of v0.0.105. Use
  `Settings` / `settings=` instead. See the [Service Settings
  guide](/pipecat/fundamentals/service-settings) for migration details.
</Tip>

## Notes

* **Model default**: `bulbul:v3` is the default model. The previous `bulbul:v2` is deprecated since 1.9.0 — Sarvam's API rejects it.
* **Model differences**: `bulbul:v2` supported pitch and loudness control; `bulbul:v3` supports temperature control but does not support pitch or loudness. Setting unsupported parameters for a model will log a warning.
* **Default voice**: v3 defaults to `shubh`; deprecated v2 defaulted to `anushka`.
* **Default sample rate**: v3 defaults to 24000 Hz; deprecated v2 defaulted to 22050 Hz.
* **Indian language focus**: Sarvam AI specializes in Indian languages, supporting Bengali, English (India), Gujarati, Hindi, Kannada, Malayalam, Marathi, Odia, Punjabi, Tamil, and Telugu.
* **Pace ranges differ**: `bulbul:v3` supports pace from 0.5 to 2.0; deprecated v2 supported 0.3 to 3.0. Values outside the range are clamped automatically.

## Event Handlers

Sarvam WebSocket TTS supports the standard [service connection events](/api-reference/server/events/service-events):

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

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