> ## 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.

# Azure Text-to-Speech

> TTS on Azure Cognitive Services: AzureTTSService for real-time WebSocket streaming and AzureHttpTTSService for simpler HTTP synthesis.

## Overview

Azure Cognitive Services provides high-quality text-to-speech synthesis with two service implementations: `AzureTTSService` (WebSocket-based) for real-time streaming with low latency, and `AzureHttpTTSService` (HTTP-based) for batch synthesis. `AzureTTSService` is recommended for interactive applications requiring streaming capabilities.

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

> [card] [Example Implementation](https://github.com/pipecat-ai/pipecat/blob/main/examples/voice/voice-azure.py)
>
> Complete example with streaming synthesis

> [card] [Azure Speech Documentation](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/)
>
> Official Azure Speech Services documentation

> [card] [Voice Gallery](https://speech.microsoft.com/portal/voicegallery)
>
> Browse available voices and languages

## Installation

To use Azure services, install the required dependencies:

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

## Prerequisites

### Azure Account Setup

Before using Azure TTS services, you need:

1. **Azure Account**: Sign up at [Azure Portal](https://portal.azure.com/)
2. **Speech Service**: Create a Speech resource in your Azure subscription
3. **API Key and Region**: Get your subscription key and service region
4. **Voice Selection**: Choose from available voices in the [Voice Gallery](https://speech.microsoft.com/portal/voicegallery)

### Required Environment Variables

* `AZURE_SPEECH_API_KEY`: Your Azure Speech service API key
* `AZURE_SPEECH_REGION`: Your Azure Speech service region (e.g., "eastus"). With Private Link, pass the endpoint URL as `private_endpoint` instead

## Configuration

### AzureTTSService

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

Azure Cognitive Services subscription key.

**region** `str`

Azure region identifier (e.g., `"eastus"`, `"westus2"`). Required unless
`private_endpoint` is provided. Raises `ValueError` when neither is set.

**private\_endpoint** `str`

Custom endpoint URL for Azure Speech Services (e.g.,
`"https://my-resource.cognitiveservices.azure.com/"`). Use this when
connecting via Private Link or a custom domain. When `region` is also set,
`region` is ignored. See [Azure Private Link
documentation](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-services-private-link).

**voice** `str` *deprecated* (default: None)

*Deprecated since 0.0.105, removed in 2.0.0.* Use
`settings=AzureTTSService.Settings(voice=...)` instead.

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

Output audio sample rate in Hz. When `None`, uses the pipeline's configured
sample rate. Must be 8000, 16000, 22050, 24000, 44100, or 48000: at any other
rate Azure returns 24 kHz audio, which plays at the wrong speed.

**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`.

**aggregate\_sentences** `bool` *deprecated* (default: None)

*Deprecated since 0.0.104, removed in 2.0.0.* Use `text_aggregation_mode`
instead.

**params** `InputParams` *deprecated* (default: None)

*Deprecated since 0.0.105, removed in 2.0.0.* Use
`settings=AzureTTSService.Settings(...)` instead.

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

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

### AzureHttpTTSService

The HTTP service accepts the same parameters as the streaming service, including `text_aggregation_mode`:

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

Azure Cognitive Services subscription key.

**region** `str`

Azure region identifier. Required unless `private_endpoint` is provided.

**private\_endpoint** `str`

Custom endpoint URL for Azure Speech Services. Use this when connecting via
Private Link or a custom domain. See [Azure Private Link
documentation](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-services-private-link).

**voice** `str` *deprecated* (default: None)

*Deprecated since 0.0.105, removed in 2.0.0.* Use
`settings=AzureHttpTTSService.Settings(voice=...)` instead.

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

Output audio sample rate in Hz. The same supported rates apply as for
`AzureTTSService`.

**params** `InputParams` *deprecated* (default: None)

*Deprecated since 0.0.105, removed in 2.0.0.* Use
`settings=AzureHttpTTSService.Settings(...)` instead.

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

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

### Settings

Runtime-configurable settings passed via the `settings` constructor argument using `AzureTTSService.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` | `None` | Not sent by this service; reported only as the model name in metrics and traces. *(Inherited.)* |
| `voice` | `str` | `"en-US-SaraNeural"` | Voice identifier. *(Inherited.)* |
| `language` | `Language \| str` | `"en-US"` | Language for synthesis. *(Inherited.)* |
| `effect` | `str` | `None` | Audio effect processor that compensates for playback distortion on a target device: `"eq_car"` for enclosed vehicles, `"eq_telecomhp8k"` for narrowband telephony (pair it with an 8 kHz pipeline). Azure ignores unrecognized values. |
| `emphasis` | `str` | `None` | Emphasis level for SSML. |
| `force_locale` | `bool` | `False` | Wraps text in SSML `<lang>` to force the configured `language` accent instead of auto-detection. |
| `pitch` | `str` | `None` | Pitch adjustment. |
| `rate` | `str` | `None` | Speaking rate. |
| `role` | `str` | `None` | Role for SSML. Applied only when `style` is set. |
| `style` | `str` | `None` | Speaking style. |
| `style_degree` | `str` | `None` | Degree of the speaking style. Applied only when `style` is set. |
| `voice_parameters` | `str` | `None` | Model parameters for HD voices, as SSML's semicolon-separated `parameters` attribute on `<voice>` (e.g., `"temperature=0.7;top_p=0.8;top_k=22;cfg_scale=1.4"` or `"enhancePronunciation=true"`). Standard voices ignore. |
| `volume` | `str` | `None` | Volume level. |

## Usage

### Basic Setup

```python theme={null}
import os

from pipecat.services.azure.tts import AzureTTSService

tts = AzureTTSService(
    api_key=os.getenv("AZURE_SPEECH_API_KEY"),
    region=os.getenv("AZURE_SPEECH_REGION"),
    settings=AzureTTSService.Settings(
        voice="en-US-SaraNeural",
    ),
)
```

### With Voice Customization

```python theme={null}
from pipecat.transcriptions.language import Language

tts = AzureTTSService(
    api_key=os.getenv("AZURE_SPEECH_API_KEY"),
    region="eastus",
    settings=AzureTTSService.Settings(
        voice="en-US-JennyMultilingualNeural",
        language=Language.EN_US,
        style="cheerful",
        style_degree="1.5",
        rate="1.1",
    ),
)
```

### HTTP Service

```python theme={null}
from pipecat.services.azure.tts import AzureHttpTTSService

tts = AzureHttpTTSService(
    api_key=os.getenv("AZURE_SPEECH_API_KEY"),
    region=os.getenv("AZURE_SPEECH_REGION"),
    settings=AzureHttpTTSService.Settings(voice="en-US-SaraNeural"),
)
```

### With Private Endpoint

```python theme={null}
from pipecat.services.azure.tts import AzureTTSService

tts = AzureTTSService(
    api_key=os.getenv("AZURE_SPEECH_API_KEY"),
    private_endpoint="https://my-resource.cognitiveservices.azure.com/",
    settings=AzureTTSService.Settings(
        voice="en-US-SaraNeural",
    ),
)
```

## Notes

* **Streaming vs HTTP**: The streaming service (`AzureTTSService`) provides word-level timestamps and lower latency, making it better for interactive conversations. The HTTP service is simpler but returns the complete audio at once.
* **SSML support**: Both services automatically construct SSML from the `Settings`. Special characters in text are automatically escaped.
* **Word timestamps**: `AzureTTSService` supports word-level timestamps for synchronized text display. CJK languages receive special handling to merge individual characters into meaningful word units.
* **8kHz workaround**: At 8kHz sample rates, Azure's reported audio duration may not match word boundary offsets. The service uses word boundary offsets for timing in this case.


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