@deepdub/node
v1.2.3
Published
Deepdub API SDK
Readme
Deepdub SDK
This is the official SDK for the Deepdub API. It provides a simple way to interact with the API and generate dubbing scripts for your videos.
Install
npm install --save @deepdub/node
# or
yarn add @deepdub/nodeUsage
const { DeepdubClient } = require('@deepdub/node');
require('dotenv').config();
async function main() {
const deepdub = new DeepdubClient('YOUR_API_KEY');
const voicePromptId = 'YOUR_PROMPT_ID';
await deepdub.connect();
// You can generate into a buffer:
//
const buffer = await deepdub.generateToBuffer('Hello, this is a test.', {
locale: 'en-US',
voicePromptId,
});
// Or you can generate into a file:
//
await deepdub.generateToFile('./generated.wav', 'Hello, this is a test.', {
locale: 'en-US',
voicePromptId,
});
}
main();Client Initialization
By default, the DeepdubClient uses WebSocket protocol for streaming audio generation. You can also use HTTP protocol by passing the protocol option:
// Default: WebSocket protocol (supports streaming)
const deepdub = new DeepdubClient('YOUR_API_KEY');
// HTTP protocol (supports additional options like sampleRate and voiceReference)
const deepdub = new DeepdubClient('YOUR_API_KEY', { protocol: 'http' });Protocol Comparison
| Feature | WebSocket | HTTP |
| ---------------------------- | --------------- | ---- |
| Streaming chunks (onChunk) | ✅ | ❌ |
| sampleRate option | ⚠️ mp3 only | ✅ |
| voiceReference option | ❌ | ✅ |
Use WebSocket (default) when you need real-time streaming. Use HTTP when you need voiceReference or sampleRate with non-mp3 formats.
Streaming Chunks
You can receive audio chunks as they arrive using the onChunk callback. This is useful for streaming audio playback or processing audio in real-time.
const buffer = await deepdub.generateToBuffer('Hello, this is a test.', {
locale: 'en-US',
voicePromptId: promptId,
onChunk: (chunk) => {
// Each chunk is a Buffer containing WAV audio data
console.log(`Received ${chunk.length} bytes`);
},
});Headerless Chunks
By default, each chunk includes a WAV header. If you need raw audio data without headers (e.g., for streaming to an audio player), use the headerless option:
const buffer = await deepdub.generateToBuffer('Hello, this is a test.', {
locale: 'en-US',
voicePromptId: promptId,
headerless: true,
onChunk: (chunk) => {
// Each chunk is raw PCM audio data (no WAV header)
audioPlayer.write(chunk);
},
});The onChunk and headerless options are also available with generateToFile.
