Skip to main content

Speechmatics Speechmatics

The SpeechmaticsTTSService provides high-quality text-to-speech using Speechmatics' preview API. It returns raw PCM audio data optimized for real-time playback.

Installation

pip install "piopiy-ai[speechmatics]"

Prerequisites

  • A Speechmatics API key (Get yours here).
  • Set your API key in your environment:
    export SPEECHMATICS_API_KEY="your_api_key_here"

Configuration

SpeechmaticsTTSService Parameters

ParameterTypeDefaultDescription
api_keystrRequiredYour Speechmatics API key.
voice_idstr"sarah"Voice model to use.
sample_rateint16000Audio sample rate (fixed at 16kHz).

Usage

Basic Setup

import os
import aiohttp
from piopiy.services.speechmatics.tts import SpeechmaticsTTSService

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

Notes

  • Sample Rate: Speechmatics TTS currently only supports a 16kHz sample rate.
  • HTTP API: This service uses an efficient HTTP-based streaming interface.
  • Retries: Includes built-in exponential backoff for handling service-level issues (503 errors).