Speechmatics TTS API Client
Project description
Speechmatics TTS API Client
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 keySPEECHMATICS_TTS_URL: Custom API endpoint URL (optional)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
speechmatics_tts-0.1.2.tar.gz
(11.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file speechmatics_tts-0.1.2.tar.gz.
File metadata
- Download URL: speechmatics_tts-0.1.2.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a6f49d05993aa1f4007ed87e31921bb3734ee8b54cc8d1affe56095faa872a7
|
|
| MD5 |
464a05e4029356fe9407a7aa2e5ec2e9
|
|
| BLAKE2b-256 |
ca8e8d8d39fa88f8b82f5685298e59cd311014b0b3c8f074d3812310e4f911a9
|
File details
Details for the file speechmatics_tts-0.1.2-py3-none-any.whl.
File metadata
- Download URL: speechmatics_tts-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4251f7e3b9b8aab2cc451b3f8d2a87e2b1db2d5c22c8d6e6caf9c5d59be6df6
|
|
| MD5 |
98d584bb66b9aed3a1170cb30d707440
|
|
| BLAKE2b-256 |
85b41b65f88bc82a2cf8f8c222730b58fa9340e67793ab013a1c910b5a2e98b2
|