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)

Metadata

Release files for speechmatics-tts 0.2.0

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.2.0
File Size Uploaded Provenance Actions
speechmatics_tts-0.2.0.tar.gz 12.1 kB Without provenance Details for speechmatics_tts-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 25.3 kB

Release files / speechmatics_tts-0.2.0.tar.gz

Download URL speechmatics_tts-0.2.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
44b062a33ec6bdebab0fb377e5e2e0e5b98baddede0fdfd23694d6c1908bda0b
BLAKE2b-256 checksum
How to use checksums
7c679e66a3dc546e80f6f41ac54b4e16f666f262d12f269bc1ffac173c909175
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL speechmatics_tts-0.2.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63b182eee901c3890447829cc6412cb08c8ab9824ad75c600f12add1f2a50946
BLAKE2b-256 checksum
How to use checksums
cc132c3b5d55ddc0dccaa92fa236a26e411fa682d66928bb09ef1cd7b0463df9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for speechmatics-tts 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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