Skip to main content

Speechmatics TTS API Client

PyPI PythonSupport

Async Python client for Speechmatics TTS API.

Features

  • Async API client with comprehensive error handling
  • Type hints throughout for better IDE support
  • Environment variable support for credentials

Installation

pip install speechmatics-tts

Usage

Quick Start

import asyncio

from speechmatics.tts import AsyncClient, Voice, OutputFormat

# Generate speech data from text and save to WAV file
async def main():
    async with AsyncClient() as client:
        async with await client.generate(
            text="Welcome to the future of voice AI!",
            voice=Voice.SARAH,
            output_format=OutputFormat.WAV_16000
        ) as response:
            audio = b''.join([chunk async for chunk in response.content.iter_chunked(1024)])
            with open("output.wav", "wb") as f:
                f.write(audio)


# Run the async main function
if __name__ == "__main__":
    asyncio.run(main())

Error Handling

import asyncio
from speechmatics.tts import (
    AsyncClient,
    AuthenticationError,
    TimeoutError
)

async def main():
    try:
        async with AsyncClient() as client:
            response = await client.generate(text="Hello, this is the Speechmatics TTS API. We are excited to have you here!")

    except AuthenticationError:
        print("Invalid API key")
    except JobError as e:
        print(f"Job processing failed: {e}")
    except TimeoutError as e:
        print(f"Job timed out: {e}")
    except FileNotFoundError:
        print("Audio file not found")

asyncio.run(main())

Connection Configuration

import asyncio
from speechmatics.tts import AsyncClient, ConnectionConfig

async def main():
    # Custom connection settings
    config = ConnectionConfig(
        url="https://preview.tts.speechmatics.com",
        api_key="your-api-key",
        connect_timeout=30.0,
        operation_timeout=600.0
    )

    async with AsyncClient(conn_config=config) as client:
        response = await client.generate(text="Hello World")
   

asyncio.run(main())

Logging

The client supports logging with job id tracing for debugging. To increase logging verbosity, set DEBUG level in your example code:

import logging
import sys

logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    handlers=[
        logging.StreamHandler(sys.stdout)
    ]
)

Environment Variables

The client supports the following environment variables:

  • SPEECHMATICS_API_KEY: Your Speechmatics API key
  • SPEECHMATICS_TTS_URL: Custom API endpoint URL (optional)

Release files for speechmatics-tts 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for speechmatics-tts 0.1.2
File Size Uploaded
speechmatics_tts-0.1.2.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for speechmatics-tts 0.1.2
File Interpreter ABI Platform
speechmatics_tts-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.8 kB

Release files / speechmatics_tts-0.1.2.tar.gz

Download URL speechmatics_tts-0.1.2.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0a6f49d05993aa1f4007ed87e31921bb3734ee8b54cc8d1affe56095faa872a7
BLAKE2b-256 checksum
How to use checksums
ca8e8d8d39fa88f8b82f5685298e59cd311014b0b3c8f074d3812310e4f911a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / speechmatics_tts-0.1.2-py3-none-any.whl

Download URL speechmatics_tts-0.1.2-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4251f7e3b9b8aab2cc451b3f8d2a87e2b1db2d5c22c8d6e6caf9c5d59be6df6
BLAKE2b-256 checksum
How to use checksums
85b41b65f88bc82a2cf8f8c222730b58fa9340e67793ab013a1c910b5a2e98b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page