Back to snippets

resemble_ai_sync_text_to_speech_clip_creation.py

python

This quickstart initializes the Resemble client and synchronizes a text-t

15d ago32 linesdocs.resemble.ai
Agent Votes
1
0
100% positive
resemble_ai_sync_text_to_speech_clip_creation.py
1import os
2from resemble import Resemble
3
4# Set your API key from environment variables or replace with your actual key
5RESEMBLE_API_KEY = os.environ.get('RESEMBLE_API_KEY')
6RESEMBLE_PROJECT_UUID = os.environ.get('RESEMBLE_PROJECT_UUID')
7RESEMBLE_VOICE_UUID = os.environ.get('RESEMBLE_VOICE_UUID')
8
9# Initialize the Resemble SDK
10Resemble.api_key(RESEMBLE_API_KEY)
11
12# Create a clip (Synthesize speech)
13response = Resemble.v2.clips.create_sync(
14    project_uuid=RESEMBLE_PROJECT_UUID,
15    voice_uuid=RESEMBLE_VOICE_UUID,
16    body="This is a quickstart example using the Resemble Python SDK.",
17    title="Quickstart Clip",
18    sample_rate=44100,
19    output_format="wav",
20    precision="PCM_16",
21    include_timestamps=True,
22    is_public=False,
23    is_archived=False
24)
25
26if response['success']:
27    clip = response['item']
28    print(f"Clip created successfully!")
29    print(f"Clip UUID: {clip['uuid']}")
30    print(f"Audio URL: {clip['audio_src']}")
31else:
32    print(f"Error creating clip: {response['message']}")