The official Python SDK for ElevenLabs. ElevenLabs brings the most compelling, rich and lifelike voices to creators and developers in just a few lines of code.
Check out the HTTP API documentation.
pip install elevenlabsEleven Multilingual v2 (
eleven_multilingual_v2)- Excels in stability, language diversity, and accent accuracy
- Supports 29 languages
- Recommended for most use cases
Eleven Flash v2.5 (
eleven_flash_v2_5)- Ultra-low latency
- Supports 32 languages
- Faster model, 50% lower price per character
Eleven Turbo v2.5 (
eleven_turbo_v2_5)- Good balance of quality and latency
- Ideal for developer use cases where speed is crucial
- Supports 32 languages
For more detailed information about these models and others, visit the ElevenLabs Models documentation.
fromdotenvimportload_dotenvfromelevenlabs.clientimportElevenLabsfromelevenlabsimportplayload_dotenv()
client=ElevenLabs()
audio=client.text_to_speech.convert(
text="The first move is what sets everything in motion.",
voice_id="JBFqnCBsd6RMkjVDRZzb",
model_id="eleven_multilingual_v2",
output_format="mp3_44100_128",
)
play(audio)Play
🎧 Try it out! Want to hear our voices in action? Visit the ElevenLabs Voice Lab to experiment with different voices, languages, and settings.
List all your available voices with voices().
fromelevenlabs.clientimportElevenLabsclient=ElevenLabs(
api_key="YOUR_API_KEY",
)
response=client.voices.search()
print(response.voices)For information about the structure of the voices output, please refer to the official ElevenLabs API documentation for Get Voices.
Build a voice object with custom settings to personalize the voice style, or call
client.voices.get_settings("your-voice-id") to get the default settings for the voice.
Clone your voice in an instant. Note that voice cloning requires an API key, see below.
fromelevenlabs.clientimportElevenLabsfromelevenlabsimportplayclient=ElevenLabs(
api_key="YOUR_API_KEY",
)
voice=client.voices.ivc.create(
name="Alex",
description="An old American male voice with a slight hoarseness in his throat. Perfect for news", # Optionalfiles=["./sample_0.mp3", "./sample_1.mp3", "./sample_2.mp3"],
)Stream audio in real-time, as it's being generated.
fromelevenlabsimportstreamfromelevenlabs.clientimportElevenLabsclient=ElevenLabs()
audio_stream=client.text_to_speech.stream(
text="This is a test",
voice_id="JBFqnCBsd6RMkjVDRZzb",
model_id="eleven_multilingual_v2"
)
# option 1: play the streamed audio locallystream(audio_stream)
# option 2: process the audio bytes manuallyforchunkinaudio_stream:
ifisinstance(chunk, bytes):
print(chunk)Use AsyncElevenLabs if you want to make API calls asynchronously.
importasynciofromelevenlabs.clientimportAsyncElevenLabseleven=AsyncElevenLabs(
api_key="MY_API_KEY"
)
asyncdefprint_models() ->None:
models=awaiteleven.models.list()
print(models)
asyncio.run(print_models())Explore all models & languages.
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
