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
UUID of the voice to use for synthesis.
model
str
default:"async_flash_v1.0"
TTS model to use.
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.
aggregate_sentences
bool
default:"True"
Whether to aggregate sentences before sending to the TTS service.
params
InputParams
default:"None"
Runtime-configurable voice settings. See InputParams 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).

InputParams

Voice and generation settings that can be set at initialization via the params constructor argument.
ParameterTypeDefaultDescription
languageLanguageNoneLanguage code for synthesis.

Usage

Basic Setup

from pipecat.services.asyncai import AsyncAITTSService

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

With Language Customization

from pipecat.transcriptions.language import Language

tts = AsyncAITTSService(
    api_key=os.getenv("ASYNCAI_API_KEY"),
    voice_id="your-voice-uuid",
    model="async_flash_v1.0",
    params=AsyncAITTSService.InputParams(
        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"),
        voice_id="your-voice-uuid",
        aiohttp_session=session,
    )

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")