Skip to main content

Official Python SDK for the Relay Speech (OpenTTS) API — one client, all TTS providers.

Project description

Relay Speech — Python SDK

Official Python client for the Relay Speech (OpenTTS) gateway. One API, all TTS providers — Cartesia, ElevenLabs, Sarvam, and more.

pip install relayspeech

Quickstart

from relayspeech import RelaySpeech

client = RelaySpeech(
    api_key="rs_live_...",            # your Relay Speech key
    provider="cartesia",              # default provider
    provider_api_key="sk-cartesia-..."
)

audio = client.tts.bytes(
    text="Hello from Relay Speech.",
    voice_id="694f9389-aac1-45b6-b726-9d9369183238",
)
open("hello.pcm", "wb").write(audio)

Environment variables (RELAY_SPEECH_API_KEY, CARTESIA_API_KEY, ELEVENLABS_API_KEY, SARVAM_API_KEY) are picked up automatically.

REST streaming

with open("out.pcm", "wb") as f:
    for chunk in client.tts.stream(text="Streaming demo.", voice_id="..."):
        f.write(chunk)

Async

from relayspeech import AsyncRelaySpeech

async with AsyncRelaySpeech(api_key="...", provider="elevenlabs",
                            provider_api_key="...") as client:
    async for chunk in await client.tts.stream(text="Hi", voice_id="..."):
        ...

WebSocket (low-latency, full duplex)

async with AsyncRelaySpeech(api_key="...", provider="cartesia",
                            provider_api_key="...") as client:
    async with client.tts.websocket() as ws:
        async for chunk in await ws.send(
            text="One sentence at a time.",
            voice_id="...",
            enable_cache=True,
        ):
            speaker.write(chunk)

Reuse the same ws for many sentences — the gateway holds the upstream provider connection open and caches each chunk independently.

Output format

from relayspeech import OutputFormat, AudioContainer, AudioEncoding

audio = client.tts.bytes(
    text="…",
    voice_id="…",
    output_format=OutputFormat(
        container=AudioContainer.WAV,
        encoding=AudioEncoding.PCM_S16LE,
        sample_rate=24000,
    ),
)

Errors

Exception When
RelaySpeechAuthError Invalid / missing Relay Speech key (401)
RelaySpeechProviderError Upstream provider failed (5xx)
RelaySpeechAPIError Any other non-2xx response
RelaySpeechConnectionError Network / WebSocket transport failure

All inherit from RelaySpeechError.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

relayspeech-0.1.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

relayspeech-0.1.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file relayspeech-0.1.0.tar.gz.

File metadata

  • Download URL: relayspeech-0.1.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.11 Darwin/24.6.0

File hashes

Hashes for relayspeech-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5c0ad597fb3f8a2f8cb24031a12961aeb67d48628d4fe1a4f2aec0c57f9c818c
MD5 3b993aef0c2a53bc7c4f04cc54757cf0
BLAKE2b-256 0e82f6bbb1ba369f89f226a517aeb3f2089209230d22cbd0b38fcb8605de770c

See more details on using hashes here.

File details

Details for the file relayspeech-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: relayspeech-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.11 Darwin/24.6.0

File hashes

Hashes for relayspeech-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de1ca576a8180a712bc461f9be0a889671b0788f655c67830d71ee6cdf68aee5
MD5 19e60d7111ac93b1c8b2d27b8ba32f2a
BLAKE2b-256 853526842f773d6b102cb7c68a22ff290d3b58d75a61475df719e5b583bf7035

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page