Skip to main content

Installation

Requirements: Node.js 18+

Initialization

apiKey
string
required
Your Deepdub API key. Must start with dd-.
options.protocol
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:
locale
string
required
Language locale code (e.g., en-US, fr-FR, he-IL).
voicePromptId
string
required
Voice prompt ID to use for generation.
model
string
default:"dd-etts-3.0"
Model ID. Available: dd-etts-3.0, dd-etts-2.5.
generationId
string
Optional UUID for tracking. Auto-generated if not provided.
format
string
Output format: mp3, wav, opus, or mulaw.
sampleRate
number
Sample rate in Hz. WebSocket protocol only supports this with mp3 format. Use HTTP protocol for other formats.
temperature
number
Generation temperature (0.0–1.0).
variance
number
Voice variation level (0.0–1.0).
tempo
number
Playback speed multiplier (0.5–2.0).
targetDuration
number
Target audio duration in seconds.
seed
number
Random seed for deterministic output.
promptBoost
boolean
Enhance voice prompt characteristics.
superStretch
boolean
Enable super stretch for longer audio.
realtime
boolean
Enable real-time priority processing.
voiceReference
string
Base64-encoded audio for instant voice cloning. HTTP protocol only.
accentControl
object
Accent blending: { accentBaseLocale, accentLocale, accentRatio }.
onChunk
function
Callback receiving each audio chunk as a Buffer. WebSocket protocol only.
headerless
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