Node.js SDK
Install the official package:
npm install @resemble/node
Initialize the client with your API token:
import { Resemble } from "@resemble/node";Resemble.setApiKey(process.env.RESEMBLE_API_KEY!);
Projects
List All Projects
const page = 1;const pageSize = 10;const response = await Resemble.v2.projects.all(page, pageSize);const projects = response.items;
Get a Project
await Resemble.v2.projects.get(projectUuid);
Create a Project
await Resemble.v2.projects.create({name: "Cooking Podcast",description: "Clips generated for our Thursday night cooking podcast",is_collaborative: true,is_archived: false});
Update a Project
await Resemble.v2.projects.update(projectUuid, {name: "Friday Night Cooking Podcast",description: "Clips generated for the podcast",is_collaborative: true,is_archived: false});
Delete a Project
await Resemble.v2.projects.delete(projectUuid);
Voices
List All Voices
const page = 1;const pageSize = 10;const response = await Resemble.v2.voices.all(page, pageSize);const voices = response.items;
Get a Voice
await Resemble.v2.voices.get(voiceUuid);
Create a Voice
await Resemble.v2.voices.create({name: "Chef",dataset_url: "https://example.com/dataset.zip",callback_uri: "http://example.com/cb",language: "en-US"});
Build a Voice
await Resemble.v2.voices.build(voiceUuid);
Delete a Voice
await Resemble.v2.voices.delete(voiceUuid);
Recordings
List All Recordings
const voiceUuid = '...';const page = 1;const pageSize = 10;const response = await Resemble.v2.recordings.all(voiceUuid, page, pageSize);const recordings = response.items;
Get a Recording
await Resemble.v2.recordings.get(voiceUuid, recordingUuid);
Create a Recording
const fs = require('fs');const file = fs.createReadStream('happy_sample.wav');const fileSize = fs.statSync('happy_sample.wav').size;await Resemble.v2.recordings.create(voiceUuid, {emotion: 'happy',is_active: true,name: 'happy_sample',text: 'Hey, this is a happy sample!'}, file, fileSize);
Update a Recording
await Resemble.v2.recordings.update(voiceUuid, recordingUuid, {emotion: 'happy',is_active: false,name: 'happy_sample',text: 'Hey, this is a happy sample!'});
Delete a Recording
await Resemble.v2.recordings.delete(voiceUuid, recordingUuid);
Clips
List All Clips
const projectUuid = '...';const page = 1;const pageSize = 10;const response = await Resemble.v2.clips.all(projectUuid, page, pageSize);const clips = response.items;
Get a Clip
await Resemble.v2.clips.get(projectUuid, clipUuid);
Create a Clip (Synchronous)
const response = await Resemble.v2.clips.createSync(projectUuid, {title: "Welcome",voice_uuid: voiceUuid,body: "Welcome to our show",is_archived: false});if (response.success) {const clip = response.item;console.log(clip.audio_src);}
Create a Clip (Direct Synthesis)
Resemble.setSynthesisUrl('https://f.cluster.resemble.ai');const response = await Resemble.v2.clips.createDirect({voice_uuid: voiceUuid,project_uuid: projectUuid,title: 'My Clip',data: 'Hello, how are you?',precision: 'PCM_32',output_format: 'wav',sample_rate: 48000});
Stream a Clip
// Configure synthesis URL for streamingResemble.setApiKey('YOUR_API_TOKEN');Resemble.setSynthesisUrl('YOUR_SYNTH_ENDPOINT');for await (const chunk of Resemble.v2.clips.stream({data: 'This is a streaming test',project_uuid: projectUuid,voice_uuid: voiceUuid})) {// Process audio chunk (Buffer)console.log('Received chunk:', chunk.length);}
Streaming Options
stream: async function* (streamInput: {data: stringproject_uuid: stringvoice_uuid: stringsample_rate?: 8000 | 16000 | 22050 | 44100 | 32000precision?: 'MULAW' | 'PCM_16' | 'PCM_24' | 'PCM_32'},streamConfig?: {bufferSize?: number // Default: 4096ignoreWavHeader?: boolean // Default: falsegetTimeStamps?: boolean // Default: false}): AsyncGenerator
Update a Clip (Async)
await Resemble.v2.clips.updateAsync(projectUuid, clipUuid, {voice_uuid: voiceUuid,body: 'This is an updated async test',callback_uri: 'https://example.com/callback/resemble-clip',title: 'Updated Title',sample_rate: 48000});
Delete a Clip
await Resemble.v2.clips.delete(projectUuid, clipUuid);
Term Substitutions
List All Term Substitutions
const page = 1;const pageSize = 10;const response = await Resemble.v2.termSubstitutions.all(page, pageSize);const substitutions = response.items;
Get a Term Substitution
const tsUuid = '...';const response = await Resemble.v2.termSubstitutions.get(tsUuid);const substitution = response.item;
Create a Term Substitution
const response = await Resemble.v2.termSubstitutions.create('Original', 'Replacement');const substitution = response.item;
Delete a Term Substitution
const substitutionUuid = '...';await Resemble.v2.termSubstitutions.delete(substitutionUuid);
Deepfake Detection
Create a Detection (URL)
const callbackUrl = 'https://example.com/webhooks/detect';const response = await Resemble.v2.detection.create({url: 'https://storage.googleapis.com/resemble-ai-docs-public-files/sts-donor-example.wav',callback_url: callbackUrl,visualize: true,frame_length: 4,start_region: 0,end_region: 10,intelligence: true,audio_source_tracing: true,use_ood_detector: true});// Full API responseconsole.log(JSON.stringify(response, null, 2));// Parsed valuesconst result = response.item;const detectionUuid = response.item?.uuid;const status = response.item?.status;
Create and Get a Detection (URL)
const callbackUrl = 'https://example.com/webhooks/detect';const response = await Resemble.v2.detection.detectAndGet({url: 'https://storage.googleapis.com/resemble-ai-docs-public-files/sts-donor-example.wav',callback_url: callbackUrl,visualize: true,frame_length: 1,start_region: 0,end_region: 10,intelligence: true,audio_source_tracing: true,use_ood_detector: true});// Full API responseconsole.log(JSON.stringify(response, null, 2));// Parsed valuesconst result = response.item;const status = response.item?.status;
Create and Get a Detection (File Upload)
import fs from 'fs';import path from 'path';const callbackUrl = 'https://example.com/webhooks/detect';const filePath = path.resolve('path/to/local-audio.wav');if (!fs.existsSync(filePath)) {throw new Error(`File not found: ${filePath}`);}const response = await Resemble.v2.detection.detectAndGet({file: filePath,callback_url: callbackUrl,visualize: true,frame_length: 4,start_region: 0,end_region: 10,intelligence: true,audio_source_tracing: true,use_ood_detector: true},10, // maxAttempts3 // waitTimeSeconds);// Full API responseconsole.log(JSON.stringify(response, null, 2));// Parsed valuesconst result = response.item;const status = response.item?.status;
Additional Resources
- Creating Clips Guide - Step-by-step tutorial
- WebSocket Streaming Guide - Real-time audio streaming
- GitHub Examples - Sample code and projects
