Use this file to discover all available pages before exploring further.
The ElevenLabs Python SDK provides powerful text-to-speech capabilities that convert written text into natural-sounding audio using advanced AI models.
from elevenlabs.client import ElevenLabsfrom elevenlabs.play import playclient = ElevenLabs( api_key="YOUR_API_KEY")audio = client.text_to_speech.convert( text="The first move is what sets everything in motion.", voice_id="JBFqnCBsd6RMkjVDRZzb", model_id="eleven_v3", output_format="mp3_44100_128")play(audio)
Optimize streaming latency at some cost of quality:
audio = client.text_to_speech.convert( text="Optimized for low latency.", voice_id="JBFqnCBsd6RMkjVDRZzb", optimize_streaming_latency=3 # 0-4, where 4 is max optimization)
Improve speech continuity when generating multiple clips:
# First generationaudio1 = client.text_to_speech.convert( text="This is the first sentence.", voice_id="JBFqnCBsd6RMkjVDRZzb", next_text="This is the second sentence.")# Second generation with contextaudio2 = client.text_to_speech.convert( text="This is the second sentence.", voice_id="JBFqnCBsd6RMkjVDRZzb", previous_text="This is the first sentence.")
from elevenlabs.play import saveaudio = client.text_to_speech.convert( text="Save this audio to disk.", voice_id="JBFqnCBsd6RMkjVDRZzb", output_format="mp3_44100_128")save(audio, "output.mp3")
Get character-level timing information for audio-text synchronization:
response = client.text_to_speech.convert_with_timestamps( text="This is a test for the API of ElevenLabs.", voice_id="21m00Tcm4TlvDq8ikWAM", output_format="mp3_44100_128")# Access audio data and alignment infoaudio_data = response.audioalignment = response.alignment