Node.js SDK
Install the official package:
$ npm install @resemble/node
Initialize the client with your API token:
1 import { Resemble } from "@resemble/node"; 2 3 Resemble.setApiKey(process.env.RESEMBLE_API_KEY!);
Projects
List All Projects
1 const page = 1; 2 const pageSize = 10; 3 4 const response = await Resemble.v2.projects.all(page, pageSize); 5 const projects = response.items;
Get a Project
1 await Resemble.v2.projects.get(projectUuid);
Create a Project
1 await Resemble.v2.projects.create({ 2 name: "Cooking Podcast", 3 description: "Clips generated for our Thursday night cooking podcast", 4 is_collaborative: true, 5 is_archived: false 6 });
Update a Project
1 await Resemble.v2.projects.update(projectUuid, { 2 name: "Friday Night Cooking Podcast", 3 description: "Clips generated for the podcast", 4 is_collaborative: true, 5 is_archived: false 6 });
Delete a Project
1 await Resemble.v2.projects.delete(projectUuid);
Voices
List All Voices
1 const page = 1; 2 const pageSize = 10; 3 4 const response = await Resemble.v2.voices.all(page, pageSize); 5 const voices = response.items;
Get a Voice
1 await Resemble.v2.voices.get(voiceUuid);
Create a Voice
1 await Resemble.v2.voices.create({ 2 name: "Chef", 3 dataset_url: "https://example.com/dataset.zip", 4 callback_uri: "http://example.com/cb", 5 language: "en-US" 6 });
Build a Voice
1 await Resemble.v2.voices.build(voiceUuid);
Delete a Voice
1 await Resemble.v2.voices.delete(voiceUuid);
Recordings
List All Recordings
1 const voiceUuid = '...'; 2 const page = 1; 3 const pageSize = 10; 4 5 const response = await Resemble.v2.recordings.all(voiceUuid, page, pageSize); 6 const recordings = response.items;
Get a Recording
1 await Resemble.v2.recordings.get(voiceUuid, recordingUuid);
Create a Recording
1 const fs = require('fs'); 2 const file = fs.createReadStream('happy_sample.wav'); 3 const fileSize = fs.statSync('happy_sample.wav').size; 4 5 await Resemble.v2.recordings.create(voiceUuid, { 6 emotion: 'happy', 7 is_active: true, 8 name: 'happy_sample', 9 text: 'Hey, this is a happy sample!' 10 }, file, fileSize);
Update a Recording
1 await Resemble.v2.recordings.update(voiceUuid, recordingUuid, { 2 emotion: 'happy', 3 is_active: false, 4 name: 'happy_sample', 5 text: 'Hey, this is a happy sample!' 6 });
Delete a Recording
1 await Resemble.v2.recordings.delete(voiceUuid, recordingUuid);
Clips
List All Clips
1 const projectUuid = '...'; 2 const page = 1; 3 const pageSize = 10; 4 5 const response = await Resemble.v2.clips.all(projectUuid, page, pageSize); 6 const clips = response.items;
Get a Clip
1 await Resemble.v2.clips.get(projectUuid, clipUuid);
Create a Clip (Synchronous)
1 const response = await Resemble.v2.clips.createSync(projectUuid, { 2 title: "Welcome", 3 voice_uuid: voiceUuid, 4 body: "Welcome to our show", 5 is_archived: false 6 }); 7 8 if (response.success) { 9 const clip = response.item; 10 console.log(clip.audio_src); 11 }
Create a Clip (Direct Synthesis)
1 Resemble.setSynthesisUrl('https://f.cluster.resemble.ai'); 2 3 const response = await Resemble.v2.clips.createDirect({ 4 voice_uuid: voiceUuid, 5 project_uuid: projectUuid, 6 title: 'My Clip', 7 data: 'Hello, how are you?', 8 precision: 'PCM_32', 9 output_format: 'wav', 10 sample_rate: 48000 11 });
Stream a Clip
1 // Configure synthesis URL for streaming 2 Resemble.setApiKey('YOUR_API_TOKEN'); 3 Resemble.setSynthesisUrl('YOUR_SYNTH_ENDPOINT'); 4 5 for await (const chunk of Resemble.v2.clips.stream({ 6 data: 'This is a streaming test', 7 project_uuid: projectUuid, 8 voice_uuid: voiceUuid 9 })) { 10 // Process audio chunk (Buffer) 11 console.log('Received chunk:', chunk.length); 12 }
Streaming Options
1 stream: async function* ( 2 streamInput: { 3 data: string 4 project_uuid: string 5 voice_uuid: string 6 sample_rate?: 8000 | 16000 | 22050 | 44100 | 32000 7 precision?: 'MULAW' | 'PCM_16' | 'PCM_24' | 'PCM_32' 8 }, 9 streamConfig?: { 10 bufferSize?: number // Default: 4096 11 ignoreWavHeader?: boolean // Default: false 12 getTimeStamps?: boolean // Default: false 13 } 14 ): AsyncGenerator
Update a Clip (Async)
1 await Resemble.v2.clips.updateAsync(projectUuid, clipUuid, { 2 voice_uuid: voiceUuid, 3 body: 'This is an updated async test', 4 callback_uri: 'https://example.com/callback/resemble-clip', 5 title: 'Updated Title', 6 sample_rate: 48000 7 });
Delete a Clip
1 await Resemble.v2.clips.delete(projectUuid, clipUuid);
Audio Edits
List All Audio Edits
1 const page = 1; 2 await Resemble.v2.edits.all(page);
Get an Audio Edit
1 const audioEditUuid = '...'; 2 await Resemble.v2.edits.get(audioEditUuid);
Create an Audio Edit
1 const fs = require('fs'); 2 const file = fs.createReadStream('original_audio.wav'); 3 const fileSize = fs.statSync('original_audio.wav').size; 4 5 await Resemble.v2.edits.create({ 6 original_transcript: 'I am happy today', 7 target_transcript: 'You are happy today', 8 voice_uuid: voiceUuid 9 }, file, fileSize);
Term Substitutions
List All Term Substitutions
1 const page = 1; 2 const pageSize = 10; 3 4 const response = await Resemble.v2.termSubstitutions.all(page, pageSize); 5 const substitutions = response.items;
Get a Term Substitution
1 const tsUuid = '...'; 2 const response = await Resemble.v2.termSubstitutions.get(tsUuid); 3 const substitution = response.item;
Create a Term Substitution
1 const response = await Resemble.v2.termSubstitutions.create('Original', 'Replacement'); 2 const substitution = response.item;
Delete a Term Substitution
1 const substitutionUuid = '...'; 2 await Resemble.v2.termSubstitutions.delete(substitutionUuid);
Deepfake Detection
Create a Detection (URL)
1 const callbackUrl = 'https://example.com/webhooks/detect'; 2 3 const response = await Resemble.v2.detection.create({ 4 url: 'https://storage.googleapis.com/resemble-ai-docs-public-files/sts-donor-example.wav', 5 callback_url: callbackUrl, 6 visualize: true, 7 frame_length: 4, 8 start_region: 0, 9 end_region: 10, 10 intelligence: true, 11 audio_source_tracing: true, 12 use_ood_detector: true 13 }); 14 15 // Full API response 16 console.log(JSON.stringify(response, null, 2)); 17 18 // Parsed values 19 const result = response.item; 20 const detectionUuid = response.item?.uuid; 21 const status = response.item?.status;
Create and Get a Detection (URL)
1 const callbackUrl = 'https://example.com/webhooks/detect'; 2 3 const response = await Resemble.v2.detection.detectAndGet({ 4 url: 'https://storage.googleapis.com/resemble-ai-docs-public-files/sts-donor-example.wav', 5 callback_url: callbackUrl, 6 visualize: true, 7 frame_length: 1, 8 start_region: 0, 9 end_region: 10, 10 intelligence: true, 11 audio_source_tracing: true, 12 use_ood_detector: true 13 }); 14 15 // Full API response 16 console.log(JSON.stringify(response, null, 2)); 17 18 // Parsed values 19 const result = response.item; 20 const status = response.item?.status;
Create and Get a Detection (File Upload)
1 import fs from 'fs'; 2 import path from 'path'; 3 4 const callbackUrl = 'https://example.com/webhooks/detect'; 5 const filePath = path.resolve('path/to/local-audio.wav'); 6 7 if (!fs.existsSync(filePath)) { 8 throw new Error(`File not found: ${filePath}`); 9 } 10 11 const response = await Resemble.v2.detection.detectAndGet( 12 { 13 file: filePath, 14 callback_url: callbackUrl, 15 visualize: true, 16 frame_length: 4, 17 start_region: 0, 18 end_region: 10, 19 intelligence: true, 20 audio_source_tracing: true, 21 use_ood_detector: true 22 }, 23 10, // maxAttempts 24 3 // waitTimeSeconds 25 ); 26 27 // Full API response 28 console.log(JSON.stringify(response, null, 2)); 29 30 // Parsed values 31 const result = response.item; 32 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
