Skip to main content

Installation

Requirements: Python 3.9+ Dependencies: requests, websockets, click, audiosample

Initialization

Constructor parameters

string
Your Deepdub API key. Falls back to DEEPDUB_API_KEY environment variable if not provided.
string
default:"https://restapi.deepdub.ai/api/v1"
Base URL for the REST API. Falls back to DEEPDUB_BASE_URL environment variable.
string
default:"wss://wsapi.deepdub.ai/open"
Base URL for the WebSocket API. Falls back to DEEPDUB_BASE_WEBSOCKET_URL environment variable.
string
default:"wss://wss.deepdub.ai/ws"
Base URL for the WebSocket streaming API. Falls back to DEEPDUB_BASE_WEBSOCKET_STREAMING_URL environment variable.
boolean
default:"false"
Use EU region endpoints (restapi.eu.deepdub.ai, wsapi.eu.deepdub.ai). Falls back to DD_EU environment variable ("1" to enable).

Region endpoints


Text-to-Speech

tts() — Synchronous generation

Generate speech and receive the complete audio as bytes.
Returns: bytes — binary audio data in the specified format.

Parameters

string
required
Text to convert to speech.
string
Voice prompt ID to use. Either this or voice_reference must be provided.
Union[bytes, str, Path]
Audio reference for instant voice cloning. Accepts a file Path, raw bytes, or a base64-encoded string. Either this or voice_prompt_id must be provided.
string
default:"dd-etts-2.5"
Model ID. Available models: dd-etts-3.0, dd-etts-2.5.
string
default:"en-US"
Language locale code (e.g., en-US, fr-FR).
string
default:"mp3"
Audio output format. REST API supports: mp3, opus, mulaw. WebSocket additionally supports: wav (default), s16le.
float
Generation temperature (0.0–1.0). Higher values produce more varied output.
float
Voice variation level (0.0–1.0).
float
Target audio duration in seconds. Mutually exclusive with tempo.
float
Playback speed multiplier. Mutually exclusive with duration.
int
Random seed for deterministic generation.
bool
Enhance voice prompt characteristics.
int
Output sample rate in Hz. Supported: 8000, 16000, 22050, 24000, 44100, 48000.
string
Base accent locale (e.g., en-US). Must be provided together with accent_locale and accent_ratio.
string
Target accent locale (e.g., fr-FR). Must be provided together with accent_base_locale and accent_ratio.
float
Accent blend ratio (0.0–1.0). Must be provided together with accent_base_locale and accent_locale.

Full example with all parameters

Voice cloning from audio reference


Async / WebSocket TTS

async_tts() — Streaming generation

Stream audio chunks over WebSocket for low-latency playback. Must be used within an async_connect() context.
Yields: bytes — audio chunks as they are generated.

Parameters

Same as tts(), plus:
string
Optional UUID for request tracking. Auto-generated if not provided.
string
Target gender for the output voice.
bool
default:"false"
Print debug information about sent/received messages.

Multiple concurrent generations

The WebSocket connection supports multiplexing — run multiple TTS requests on the same connection:

Streaming Input

For real-time text streaming (sending text incrementally), use async_stream_connect():

Gender Classification

Classify the gender of a speaker from an audio sample:
Union[bytes, str, Path]
required
Audio data as raw bytes, base64-encoded string, or file Path. Automatically trimmed to 1 second.
int
default:"16000"
Sample rate of the input audio.
float
default:"5.0"
Timeout in seconds for the WebSocket response.
string
Optional UUID for request tracking.

Voice Management

list_voices() — List all voice prompts

Returns: dict with a voicePrompts key containing a list of voice prompt objects.

add_voice() — Upload a voice sample

Returns: dict with the created voice prompt information.

Parameters

Union[bytes, str, Path]
required
Audio data — a file Path, raw bytes, or base64-encoded string.
string
required
Display name for the voice prompt.
string
required
Speaker gender: "male" or "female".
string
required
Language locale code (e.g., en-US).
bool
default:"false"
Whether to make the voice publicly available.
string
default:"Neutral"
Speaking style descriptor.
int
default:"0"
Age of the speaker.

CLI Reference

The SDK includes a command-line interface:

Environment Variables


Error Handling

For async operations, WebSocket errors are raised as Exception with the error message from the server:

Available Models