Skip to main content

No project description provided

Project description

ElevenLabs Python Library

LOGO

fern shield Discord Twitter PyPI - Python Version Downloads

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.

📖 API & Docs

Check out the HTTP API documentation.

Install

pip install elevenlabs

Usage

Main Models

  1. Eleven v3 (eleven_v3)

    • Dramatic delivery and performances
    • 70+ languages supported
    • Supported for natural multi-speaker dialogue
  2. Eleven Multilingual v2 (eleven_multilingual_v2)

    • Excels in stability, language diversity, and accent accuracy
    • Supports 29 languages
    • Recommended for most use cases
  3. Eleven Flash v2.5 (eleven_flash_v2_5)

    • Ultra-low latency
    • Supports 32 languages
    • Faster model, 50% lower price per character
  4. 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.

from dotenv import load_dotenv
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play

load_dotenv()

elevenlabs = ElevenLabs()

audio = elevenlabs.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)
Play

🎧 Try it out! Want to hear our voices in action? Visit the ElevenLabs Voice Lab to experiment with different voices, languages, and settings.

Voices

List all your available voices with search().

from elevenlabs.client import ElevenLabs

elevenlabs = ElevenLabs(
  api_key="YOUR_API_KEY",
)

response = elevenlabs.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 elevenlabs.voices.settings.get("your-voice-id") to get the default settings for the voice.

Clone Voice

Clone your voice in an instant. Note that voice cloning requires an API key, see below.

from elevenlabs.client import ElevenLabs
from elevenlabs.play import play

elevenlabs = ElevenLabs(
  api_key="YOUR_API_KEY",
)

voice = elevenlabs.voices.ivc.create(
    name="Alex",
    description="An old American male voice with a slight hoarseness in his throat. Perfect for news", # Optional
    files=["./sample_0.mp3", "./sample_1.mp3", "./sample_2.mp3"],
)

Streaming

Stream audio in real-time, as it's being generated.

from elevenlabs import stream
from elevenlabs.client import ElevenLabs

elevenlabs = ElevenLabs(
  api_key="YOUR_API_KEY",
)

audio_stream = elevenlabs.text_to_speech.stream(
    text="This is a test",
    voice_id="JBFqnCBsd6RMkjVDRZzb",
    model_id="eleven_multilingual_v2"
)

# option 1: play the streamed audio locally
stream(audio_stream)

# option 2: process the audio bytes manually
for chunk in audio_stream:
    if isinstance(chunk, bytes):
        print(chunk)

Async Client

Use AsyncElevenLabs if you want to make API calls asynchronously.

import asyncio

from elevenlabs.client import AsyncElevenLabs

elevenlabs = AsyncElevenLabs(
  api_key="MY_API_KEY"
)

async def print_models() -> None:
    models = await elevenlabs.models.list()
    print(models)

asyncio.run(print_models())

ElevenAgents

Build interactive AI agents with real-time audio capabilities using ElevenAgents.

Basic Usage

from elevenlabs.client import ElevenLabs
from elevenlabs.conversational_ai.conversation import Conversation, ClientTools
from elevenlabs.conversational_ai.default_audio_interface import DefaultAudioInterface

elevenlabs = ElevenLabs(
  api_key="YOUR_API_KEY",
)

# Create audio interface for real-time audio input/output
audio_interface = DefaultAudioInterface()

# Create conversation
conversation = Conversation(
    client=elevenlabs,
    agent_id="your-agent-id",
    requires_auth=True,
    audio_interface=audio_interface,
)

# Start the conversation
conversation.start_session()

# The conversation runs in background until you call:
conversation.end_session()

Custom Event Loop Support

For advanced use cases involving context propagation, resource reuse, or specific event loop management, ClientTools supports custom asyncio event loops:

import asyncio
from elevenlabs.conversational_ai.conversation import ClientTools

elevenlabs = ElevenLabs(
  api_key="YOUR_API_KEY",
)

async def main():
    # Get the current event loop
    custom_loop = asyncio.get_running_loop()

    # Create ClientTools with custom loop to prevent "different event loop" errors
    client_tools = ClientTools(loop=custom_loop)

    # Register your tools
    async def get_weather(params):
        location = params.get("location", "Unknown")
        # Your async logic here
        return f"Weather in {location}: Sunny, 72°F"

    client_tools.register("get_weather", get_weather, is_async=True)

    # Use with conversation
    conversation = Conversation(
        client=elevenlabs,
        agent_id="your-agent-id",
        requires_auth=True,
        audio_interface=audio_interface,
        client_tools=client_tools
    )

asyncio.run(main())

Benefits of Custom Event Loop:

  • Context Propagation: Maintain request-scoped state across async operations
  • Resource Reuse: Share existing async resources like HTTP sessions or database pools
  • Loop Management: Prevent "Task got Future attached to a different event loop" errors
  • Performance: Better control over async task scheduling and execution

Important: When using a custom loop, you're responsible for its lifecycle Don't close the loop while ClientTools are still using it.

Tool Registration

Register custom tools that the AI agent can call during conversations:

client_tools = ClientTools()

# Sync tool
def calculate_sum(params):
    numbers = params.get("numbers", [])
    return sum(numbers)

# Async tool
async def fetch_data(params):
    url = params.get("url")
    # Your async HTTP request logic
    return {"data": "fetched"}

client_tools.register("calculate_sum", calculate_sum, is_async=False)
client_tools.register("fetch_data", fetch_data, is_async=True)

Languages Supported

Explore all models & languages.

Contributing

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!

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elevenlabs-2.42.0.tar.gz (537.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elevenlabs-2.42.0-py3-none-any.whl (1.5 MB view details)

Uploaded Python 3

File details

Details for the file elevenlabs-2.42.0.tar.gz.

File metadata

  • Download URL: elevenlabs-2.42.0.tar.gz
  • Upload date:
  • Size: 537.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for elevenlabs-2.42.0.tar.gz
Algorithm Hash digest
SHA256 eeee74c51724429c06950bad4c4798b66641ac6b220811b05a7ce1c5dfb03026
MD5 d5e4aeb3298070ca340c6cf3016ac736
BLAKE2b-256 f5df1774d90a3a6db0f990dc25e2830ce1edb7a9951e05b7a357db1ea314e227

See more details on using hashes here.

Provenance

The following attestation bundles were made for elevenlabs-2.42.0.tar.gz:

Publisher: ci.yml on elevenlabs/elevenlabs-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file elevenlabs-2.42.0-py3-none-any.whl.

File metadata

  • Download URL: elevenlabs-2.42.0-py3-none-any.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for elevenlabs-2.42.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d255e64ef406375db8b59264babc944cb295eeffc0786b4f8f82485ac62c49ae
MD5 7f1b8daff654abf44d84dba61f1be67b
BLAKE2b-256 86274fa9ee48d0e9f2ec7efd4d59b0a6ded7807e395e56be57330482a51d7bd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for elevenlabs-2.42.0-py3-none-any.whl:

Publisher: ci.yml on elevenlabs/elevenlabs-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page