Python SDK
Install the package:
$ pip install resemble
Configure the SDK:
1 from resemble import Resemble 2 3 Resemble.api_key("YOUR_API_TOKEN")
Projects
List All Projects
1 page = 1 2 page_size = 10 3 4 response = Resemble.v2.projects.all(page, page_size) 5 projects = response['items']
Get a Project
1 project_uuid = '<project_uuid>' 2 3 response = Resemble.v2.projects.get(project_uuid) 4 project = response['item']
Create a Project
1 name = 'My project' 2 description = 'My description' 3 is_archived = False 4 is_collaborative = False 5 6 response = Resemble.v2.projects.create(name, description, is_collaborative, is_archived) 7 project = response['item']
Update a Project
1 project_uuid = '<project_uuid>' 2 name = 'My project (archived)' 3 description = 'My description (this project has been archived)' 4 is_archived = True 5 is_collaborative = False 6 7 response = Resemble.v2.projects.update(project_uuid, name, description, is_collaborative, is_archived) 8 project = response['item']
Delete a Project
1 project_uuid = '<project_uuid>' 2 3 response = Resemble.v2.projects.delete(project_uuid)
Voices
List All Voices
1 page = 1 2 page_size = 10 3 4 response = Resemble.v2.voices.all(page, page_size) 5 voices = response['items']
Get a Voice
1 voice_uuid = '<voice_uuid>' 2 3 response = Resemble.v2.voices.get(voice_uuid) 4 voice = response['item']
Create a Voice
1 name = 'Test Voice' 2 3 response = Resemble.v2.voices.create( 4 name, 5 dataset_url="https://example.com/dataset.zip", 6 callback_uri="http://example.com/cb", 7 language="en-US" 8 ) 9 voice = response['item']
Build a Voice
1 voice_uuid = '<voice_uuid>' 2 3 response = Resemble.v2.voices.build(voice_uuid)
Delete a Voice
1 voice_uuid = '<voice_uuid>' 2 3 response = Resemble.v2.voices.delete(voice_uuid)
Recordings
List All Recordings
1 voice_uuid = '<voice_uuid>' 2 page = 1 3 page_size = 10 4 5 response = Resemble.v2.recordings.all(voice_uuid, page, page_size) 6 recordings = response['items']
Get a Recording
1 voice_uuid = '<voice_uuid>' 2 recording_uuid = '<recording_uuid>' 3 4 response = Resemble.v2.recordings.get(voice_uuid, recording_uuid) 5 recording = response['item']
Create a Recording
1 voice_uuid = '<voice_uuid>' 2 name = 'recording' 3 text = 'This is a test' 4 is_active = True 5 emotion = 'neutral' 6 7 with open("path/to/audio.wav", 'rb') as file: 8 response = Resemble.v2.recordings.create(voice_uuid, file, name, text, is_active, emotion) 9 recording = response['item']
Update a Recording
1 voice_uuid = '<voice_uuid>' 2 recording_uuid = '<uuid>' 3 name = 'recording' 4 text = 'This is a test' 5 is_active = True 6 emotion = 'neutral' 7 8 response = Resemble.v2.recordings.update(voice_uuid, recording_uuid, name, text, is_active, emotion) 9 recording = response['item']
Delete a Recording
1 voice_uuid = '<voice_uuid>' 2 recording_uuid = '<recording_uuid>' 3 4 response = Resemble.v2.recordings.delete(voice_uuid, recording_uuid)
Clips
List All Clips
1 project_uuid = '<project_uuid>' 2 page = 1 3 page_size = 10 4 5 response = Resemble.v2.clips.all(project_uuid, page, page_size) 6 clips = response['items']
Get a Clip
1 project_uuid = '<project_uuid>' 2 clip_uuid = '<clip_uuid>' 3 4 response = Resemble.v2.clips.get(project_uuid, clip_uuid) 5 clip = response['item']
Create a Clip (Synchronous)
1 response = Resemble.v2.clips.create_sync( 2 project_uuid, 3 voice_uuid, 4 "Welcome to Resemble", 5 title="Intro" 6 ) 7 8 if response["success"]: 9 clip = response["item"] 10 print(clip["audio_src"]) 11 else: 12 print(response)
Create a Clip (Direct Synthesis)
1 voice_uuid = '<voice_uuid>' 2 project_uuid = '<project_uuid>' 3 output_format = 'wav' 4 data = 'Hello, how are you?' 5 title = 'Greeting' 6 precision = 'PCM_32' 7 sample_rate = 48000 8 9 response = Resemble.v2.clips.create_direct( 10 project_uuid, 11 voice_uuid, 12 data, 13 title, 14 precision, 15 output_format, 16 sample_rate 17 ) 18 19 clip = response['audio_content']
Stream a Clip
1 # Configure synthesis URL for streaming 2 Resemble.api_key('YOUR_API_TOKEN') 3 Resemble.syn_server_url('<syn_server_url>') # Obtain from https://app.resemble.ai/account/api 4 5 project_uuid = '<project_uuid>' 6 voice_uuid = '<voice_uuid>' 7 body = 'This is a streaming test' 8 9 try: 10 for chunk in Resemble.v2.clips.stream(project_uuid, voice_uuid, body): 11 # chunk is a byte array of shorts (int 16) representing WAV audio 12 # Process the audio chunk here 13 pass 14 except Exception as e: 15 # Handle exceptions 16 print(f"Error: {e}")
Update a Clip (Async)
1 project_uuid = '<project_uuid>' 2 clip_uuid = '<clip_uuid>' 3 voice_uuid = '<voice_uuid>' 4 callback_uri = 'https://example.com/callback/resemble-clip' 5 body = 'This is an updated async test' 6 7 response = Resemble.v2.clips.update_async( 8 project_uuid, 9 clip_uuid, 10 voice_uuid, 11 callback_uri, 12 body, 13 title=None, 14 sample_rate=None, 15 output_format=None, 16 precision=None, 17 include_timestamps=None, 18 is_archived=None 19 ) 20 clip = response['item']
Delete a Clip
1 project_uuid = '<project_uuid>' 2 clip_uuid = '<clip_uuid>' 3 4 response = Resemble.v2.clips.delete(project_uuid, clip_uuid)
Audio Edits
List All Audio Edits
1 page = 1 2 response = Resemble.v2.edits.all(page) 3 audio_edits = response['items']
Get an Audio Edit
1 audio_edit_uuid = '<audio_edit_uuid>' 2 response = Resemble.v2.edits.get(audio_edit_uuid) 3 audio_edit = response['item']
Create an Audio Edit
1 original_transcript = 'Hi, how are you?' 2 target_transcript = 'Hello, how are you?' 3 voice_uuid = '<voice_uuid>' 4 5 with open('path/to/audio.wav', 'rb') as file: 6 response = Resemble.v2.edits.create(original_transcript, target_transcript, voice_uuid, file) 7 audio_edit = response['item']
Create and Get an Audio Edit
1 original_transcript = 'Hi, how are you?' 2 target_transcript = 'Hello, how are you?' 3 voice_uuid = '<voice_uuid>' 4 5 with open('path/to/audio.wav', 'rb') as file: 6 response = Resemble.v2.edits.create_and_get(original_transcript, target_transcript, voice_uuid, file) 7 audio_edit = response['item']
Term Substitutions
List All Term Substitutions
1 page = 1 2 page_size = 10 3 4 response = Resemble.v2.term_substitutions.all(page, page_size) 5 substitutions = response['items']
Create a Term Substitution
1 response = Resemble.v2.term_substitutions.create('Original', 'Replacement') 2 substitutions = response['items']
Delete a Term Substitution
1 substitution_uuid = '...' 2 3 response = Resemble.v2.term_substitutions.delete(substitution_uuid)
Deepfake Detection
Create a Detection
1 media_url = "https://example.com/sample-video.mp4" 2 3 response = Resemble.v2.deepfake_detection.detect(url=media_url) 4 5 if response["success"]: 6 detection_uuid = response["item"]["uuid"] 7 status = response["item"]["status"]
Get a Detection Result
1 import time 2 3 detection_uuid = "<detection_uuid>" 4 max_attempts = 10 5 wait_time_seconds = 3 6 7 for _ in range(max_attempts): 8 response = Resemble.v2.deepfake_detection.get(detection_uuid) 9 status = response.get("item", {}).get("status") 10 11 if status in ("completed", "failed"): 12 break 13 14 time.sleep(wait_time_seconds)
Create and Get a Detection (URL)
1 import json 2 3 media_url = "https://example.com/sample-audio.wav" 4 5 response = Resemble.v2.deepfake_detection.detect_and_get( 6 url=media_url, 7 audio_source_tracing=True, 8 intelligence=True, 9 use_ood_detector=True, 10 ) 11 12 # Full API response 13 print(json.dumps(response, indent=2)) 14 15 # Parsed values 16 result = response.get("item", {}) 17 status = response.get("item", {}).get("status")
Create and Get a Detection (File Upload)
1 import json 2 3 file_path = "path/to/local-audio.wav" 4 5 with open(file_path, "rb") as file: 6 response = Resemble.v2.deepfake_detection.detect_and_get( 7 file=file, 8 audio_source_tracing=True, 9 intelligence=True, 10 use_ood_detector=True, 11 ) 12 13 # Full API response 14 print(json.dumps(response, indent=2)) 15 16 # Parsed values 17 result = response.get("item", {}) 18 status = response.get("item", {}).get("status")
Additional Resources
- Creating Clips Guide - Step-by-step tutorial
- WebSocket Streaming Guide - Real-time audio streaming
- GitHub Examples - Sample code and projects
