Skip to main content
The official Python SDK is published as supertone on PyPI. Source: supertone-inc/supertone-python.

At a glance

Installation

Requires Python 3.9+.

Set your API key

The SDK does not auto-read from the environment. Pass api_key explicitly — the convention is to read from SUPERTONE_API_KEY.
Voice IDs are not environment variables — they change per use case, so keep them as plain strings in your code (or pass them from your request payload).

Generate speech (sync)

The recommended pattern uses a context manager so the underlying HTTP connection is closed cleanly:

Generate speech (async)

Use the _async suffix and async with:
Every resource method on the SDK has both forms: create_speech / create_speech_async, stream_speech / stream_speech_async, list_voices / list_voices_async, and so on.

Stream speech

Streaming returns an iterator (or async iterator) of audio chunks:
Async equivalent uses async for chunk in response.result.aiter_bytes(). Streaming is currently supported on sona_speech_1 only.

Long text auto-chunking

create_speech, create_speech_async, stream_speech, and stream_speech_async automatically split text longer than 300 characters. create_speech runs up to 3 segments in parallel and merges the audio; stream_speech runs segments sequentially and forwards chunks to your iterator.
predict_duration does not auto-chunk — keep that input under 300 characters and sum durations manually for longer scripts. See Long text for details and tuning.

Common operations

Type-safe enums (optional)

For type safety, the SDK exposes enum constants in supertone.models:
Plain strings ("en", "sona_speech_1") work too — use whichever style you prefer.

Error handling

Errors live in supertone.errors and all extend SupertoneError:
Network errors (DNS failure, broken pipe, etc.) come from httpx and don’t inherit from SupertoneError.

Configuration

TypeScript SDK

The equivalent SDK for Node and Bun.

Examples

Recipes for common workflows.