Skip to main content

Overview

SpeechmaticsTTSService provides production-grade, low-latency synthesis optimized for telephony and voice agents. By streaming 16kHz mono audio, it ensures bandwidth efficiency and prioritizes pronunciation accuracy for natural, uninterrupted conversations at scale.

Installation

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

Prerequisites

Speechmatics Account Setup

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

Required Environment Variables

  • SPEECHMATICS_API_KEY: Your Speechmatics API key for authentication

Configuration

SpeechmaticsTTSService

api_key
str
required
Speechmatics API key for authentication.
base_url
str
default:"https://preview.tts.speechmatics.com"
Base URL for Speechmatics TTS API.
voice_id
str
default:"sarah"
Voice model to use for synthesis.
aiohttp_session
aiohttp.ClientSession
required
An aiohttp session for HTTP requests.
sample_rate
int
default:"16000"
Audio sample rate in Hz. Speechmatics TTS only supports 16kHz.
params
InputParams
default:"None"
Runtime-configurable service settings. See InputParams below.

InputParams

ParameterTypeDefaultDescription
max_retriesint5Maximum number of retries for TTS requests when receiving 503 responses.

Usage

Basic Setup

import aiohttp
from pipecat.services.speechmatics import SpeechmaticsTTSService

async with aiohttp.ClientSession() as session:
    tts = SpeechmaticsTTSService(
        api_key=os.getenv("SPEECHMATICS_API_KEY"),
        voice_id="sarah",
        aiohttp_session=session,
    )

With Custom Settings

import aiohttp
from pipecat.services.speechmatics import SpeechmaticsTTSService

async with aiohttp.ClientSession() as session:
    tts = SpeechmaticsTTSService(
        api_key=os.getenv("SPEECHMATICS_API_KEY"),
        voice_id="sarah",
        aiohttp_session=session,
        params=SpeechmaticsTTSService.InputParams(
            max_retries=3,
        ),
    )

Notes

  • Fixed sample rate: Speechmatics TTS only supports 16kHz output. Using a different sample rate may cause issues.
  • Automatic retry with backoff: The service automatically retries on 503 (service unavailable) responses using exponential backoff, up to max_retries attempts.
  • HTTP-based service: Speechmatics TTS uses HTTP streaming, so it does not have WebSocket connection events.
  • Requires aiohttp session: You must create and manage an aiohttp.ClientSession yourself and pass it to the constructor.