Skip to main content

Installation

Requirements: Node.js 18+

Initialization

string
required
Your Deepdub API key. Must start with dd-.
string
default:"websocket"
Transport protocol: "websocket" for real-time streaming, or "http" for REST API.

Protocol comparison

Use WebSocket (default) for real-time streaming and low-latency playback. Use HTTP when you need voiceReference for instant voice cloning or sampleRate with non-mp3 formats.

Connection

For WebSocket protocol, you must call connect() before generating audio:
For HTTP protocol, no connection step is needed.

Generate to buffer

Generate audio and receive a Buffer of WAV data:
Returns: Promise<Buffer> — WAV audio data.

Generate to file

Generate audio and save directly to a file:
Returns: Promise<void>

Generation parameters

Both generateToBuffer and generateToFile accept these options:
string
required
Language locale code (e.g., en-US, fr-FR, he-IL).
string
required
Voice prompt ID to use for generation.
string
default:"dd-etts-3.0"
Model ID. Available: dd-etts-3.0, dd-etts-2.5.
string
Optional UUID for tracking. Auto-generated if not provided.
string
Output format: mp3, wav, opus, or mulaw.
number
Sample rate in Hz. WebSocket protocol only supports this with mp3 format. Use HTTP protocol for other formats.
number
Generation temperature (0.0–1.0).
number
Voice variation level (0.0–1.0).
number
Playback speed multiplier (0.5–2.0).
number
Target audio duration in seconds.
number
Random seed for deterministic output.
boolean
Enhance voice prompt characteristics.
boolean
Enable super stretch for longer audio.
boolean
Enable real-time priority processing.
string
Base64-encoded audio for instant voice cloning. HTTP protocol only.
object
Accent blending: { accentBaseLocale, accentLocale, accentRatio }.
function
Callback receiving each audio chunk as a Buffer. WebSocket protocol only.
boolean
default:"false"
When true, chunks passed to onChunk have WAV headers stripped (raw PCM). WebSocket protocol only.

Streaming chunks

Receive audio data incrementally for real-time playback:

Headerless chunks

Strip WAV headers from each chunk for raw PCM data (useful for audio players):

Concurrent generations

Run multiple generations in parallel on the same WebSocket connection:

Full example

Using HTTP protocol

For voice cloning from an audio reference:

Error handling


Environment variables