Skip to main content

Overview

Async provides high-quality text-to-speech synthesis with two service implementations: AsyncAITTSService (WebSocket-based) for real-time streaming with interruption support, and AsyncAIHttpTTSService (HTTP-based) for simpler synthesis. AsyncAITTSService is recommended for interactive applications requiring low latency.

Installation

To use Async services, install the required dependencies:
pip install "pipecat-ai[asyncai]"

Prerequisites

Async Account Setup

Before using Async TTS services, you need:
  1. Async Account: Sign up at Async
  2. API Key: Generate an API key from your account dashboard
  3. Voice Selection: Choose from available voice models

Required Environment Variables

  • ASYNCAI_API_KEY: Your Async API key for authentication

Configuration

AsyncAITTSService

api_key
str
required
Async API key.
voice_id
str
required
deprecated
UUID of the voice to use for synthesis. Deprecated in v0.0.105. Use settings=AsyncAITTSService.Settings(voice=...) instead.
model
str
default:"async_flash_v1.0"
deprecated
TTS model to use. Deprecated in v0.0.105. Use settings=AsyncAITTSService.Settings(model=...) instead.
version
str
default:"v1"
Async API version.
url
str
default:"wss://api.async.com/text_to_speech/websocket/ws"
WebSocket endpoint URL.
sample_rate
int
default:"None"
Output audio sample rate in Hz. When None, uses the pipeline’s configured sample rate.
encoding
str
default:"pcm_s16le"
Audio encoding format.
container
str
default:"raw"
Audio container format.
text_aggregation_mode
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.
aggregate_sentences
bool
default:"None"
deprecated
Deprecated in v0.0.104. Use text_aggregation_mode instead.
params
InputParams
default:"None"
deprecated
Deprecated in v0.0.105. Use settings=AsyncAITTSService.Settings(...) instead.
settings
AsyncAITTSService.Settings
default:"None"
Runtime-configurable settings. See Settings below.

AsyncAIHttpTTSService

The HTTP service accepts similar parameters to the WebSocket service, with these differences:
aiohttp_session
aiohttp.ClientSession
required
An aiohttp session for HTTP requests. You must create and manage this yourself.
url
str
default:"https://api.async.com"
HTTP API base URL (instead of WebSocket URL).

Settings

Runtime-configurable settings passed via the settings constructor argument using AsyncAITTSService.Settings(...). These can be updated mid-conversation with TTSUpdateSettingsFrame. See Service Settings for details.
ParameterTypeDefaultDescription
modelstrNoneModel identifier. (Inherited.)
voicestrNoneVoice identifier. (Inherited.)
languageLanguage | strNoneLanguage for synthesis. (Inherited.)

Usage

Basic Setup

from pipecat.services.asyncai import AsyncAITTSService

tts = AsyncAITTSService(
    api_key=os.getenv("ASYNCAI_API_KEY"),
    settings=AsyncAITTSService.Settings(
        voice="your-voice-uuid",
    ),
)

With Language Customization

from pipecat.transcriptions.language import Language

tts = AsyncAITTSService(
    api_key=os.getenv("ASYNCAI_API_KEY"),
    settings=AsyncAITTSService.Settings(
        voice="your-voice-uuid",
        model="async_flash_v1.0",
        language=Language.ES,
    ),
)

HTTP Service

import aiohttp
from pipecat.services.asyncai import AsyncAIHttpTTSService

async with aiohttp.ClientSession() as session:
    tts = AsyncAIHttpTTSService(
        api_key=os.getenv("ASYNCAI_API_KEY"),
        settings=AsyncAIHttpTTSService.Settings(
            voice="your-voice-uuid",
        ),
        aiohttp_session=session,
    )
The InputParams / params= pattern is deprecated as of v0.0.105. Use Settings / settings= instead. See the Service Settings guide for migration details.

Event Handlers

Async TTS supports the standard service connection events:
EventDescription
on_connectedConnected to Async WebSocket
on_disconnectedDisconnected from Async WebSocket
on_connection_errorWebSocket connection error occurred
@tts.event_handler("on_connected")
async def on_connected(service):
    print("Connected to Async")