Skip to main content

Installation

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

Initialization

Constructor parameters

api_key
string
Your Deepdub API key. Falls back to DEEPDUB_API_KEY environment variable if not provided.
base_url
string
default:"https://restapi.deepdub.ai/api/v1"
Base URL for the REST API. Falls back to DEEPDUB_BASE_URL environment variable.
base_websocket_url
string
default:"wss://wsapi.deepdub.ai/open"
Base URL for the WebSocket API. Falls back to DEEPDUB_BASE_WEBSOCKET_URL environment variable.
base_websocket_streaming_url
string
default:"wss://wss.deepdub.ai/ws"
Base URL for the WebSocket streaming API. Falls back to DEEPDUB_BASE_WEBSOCKET_STREAMING_URL environment variable.
eu
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

text
string
required
Text to convert to speech.
voice_prompt_id
string
Voice prompt ID to use. Either this or voice_reference must be provided.
voice_reference
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.
model
string
default:"dd-etts-2.5"
Model ID. Available models: dd-etts-3.0, dd-etts-2.5.
locale
string
default:"en-US"
Language locale code (e.g., en-US, fr-FR).
format
string
default:"mp3"
Audio output format. REST API supports: mp3, opus, mulaw. WebSocket additionally supports: wav (default), s16le.
temperature
float
Generation temperature (0.0–1.0). Higher values produce more varied output.
variance
float
Voice variation level (0.0–1.0).
duration
float
Target audio duration in seconds. Mutually exclusive with tempo.
tempo
float
Playback speed multiplier. Mutually exclusive with duration.
seed
int
Random seed for deterministic generation.
prompt_boost
bool
Enhance voice prompt characteristics.
sample_rate
int
Output sample rate in Hz. Supported: 8000, 16000, 22050, 24000, 44100, 48000.
accent_base_locale
string
Base accent locale (e.g., en-US). Must be provided together with accent_locale and accent_ratio.
accent_locale
string
Target accent locale (e.g., fr-FR). Must be provided together with accent_base_locale and accent_ratio.
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:
generation_id
string
Optional UUID for request tracking. Auto-generated if not provided.
target_gender
string
Target gender for the output voice.
verbose
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:
audio_data
Union[bytes, str, Path]
required
Audio data as raw bytes, base64-encoded string, or file Path. Automatically trimmed to 1 second.
sample_rate
int
default:"16000"
Sample rate of the input audio.
timeout
float
default:"5.0"
Timeout in seconds for the WebSocket response.
generation_id
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

data
Union[bytes, str, Path]
required
Audio data — a file Path, raw bytes, or base64-encoded string.
name
string
required
Display name for the voice prompt.
gender
string
required
Speaker gender: "male" or "female".
locale
string
required
Language locale code (e.g., en-US).
publish
bool
default:"false"
Whether to make the voice publicly available.
speaking_style
string
default:"Neutral"
Speaking style descriptor.
age
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