{"id":13405586,"url":"https://github.com/elevenlabs/elevenlabs-python","last_synced_at":"2026-01-30T15:05:25.000Z","repository":{"id":153483253,"uuid":"619143361","full_name":"elevenlabs/elevenlabs-python","owner":"elevenlabs","description":"The official Python API for ElevenLabs Text to Speech.","archived":false,"fork":false,"pushed_at":"2025-05-05T07:13:30.000Z","size":3673,"stargazers_count":2510,"open_issues_count":27,"forks_count":317,"subscribers_count":50,"default_branch":"main","last_synced_at":"2025-05-05T08:25:33.970Z","etag":null,"topics":["artificial-intelligence","text-to-speech"],"latest_commit_sha":null,"homepage":"https://elevenlabs.io/docs/api-reference/overview","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elevenlabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-03-26T11:59:52.000Z","updated_at":"2025-05-05T07:13:35.000Z","dependencies_parsed_at":"2023-11-19T00:28:01.682Z","dependency_job_id":"f90d6ff0-7bd6-4714-9968-56b9c34631a6","html_url":"https://github.com/elevenlabs/elevenlabs-python","commit_stats":{"total_commits":155,"total_committers":36,"mean_commits":4.305555555555555,"dds":0.6580645161290323,"last_synced_commit":"0a5a4e0767db958c69f64b381cdeb7446b9422c5"},"previous_names":[],"tags_count":80,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elevenlabs%2Felevenlabs-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elevenlabs%2Felevenlabs-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elevenlabs%2Felevenlabs-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elevenlabs%2Felevenlabs-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elevenlabs","download_url":"https://codeload.github.com/elevenlabs/elevenlabs-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254049539,"owners_count":22006080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","text-to-speech"],"created_at":"2024-07-30T19:02:06.002Z","updated_at":"2026-01-05T12:21:04.990Z","avatar_url":"https://github.com/elevenlabs.png","language":"Python","funding_links":[],"categories":["Python","语音合成","Voice and Multimodal Agents","Developer CLIs"],"sub_categories":["资源传输下载","Codex Resources","Community"],"readme":"# ElevenLabs Python Library\n\n![LOGO](https://github.com/elevenlabs/elevenlabs-python/assets/12028621/21267d89-5e82-4e7e-9c81-caf30b237683)\n\n[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://buildwithfern.com/?utm_source=fern-elevenlabs/elevenlabs-python/readme)\n[![Discord](https://badgen.net/badge/black/ElevenLabs/icon?icon=discord\u0026label)](https://discord.gg/elevenlabs)\n[![Twitter](https://badgen.net/badge/black/elevenlabsio/icon?icon=twitter\u0026label)](https://twitter.com/elevenlabsio)\n[![PyPI - Python Version](https://img.shields.io/pypi/v/elevenlabs?style=flat\u0026colorA=black\u0026colorB=black)](https://pypi.org/project/elevenlabs/)\n[![Downloads](https://static.pepy.tech/personalized-badge/elevenlabs?period=total\u0026units=international_system\u0026left_color=black\u0026right_color=black\u0026left_text=Downloads)](https://pepy.tech/project/elevenlabs)\n\nThe official Python SDK for [ElevenLabs](https://elevenlabs.io/). ElevenLabs brings the most compelling, rich and lifelike voices to creators and developers in just a few lines of code.\n\n## 📖 API \u0026 Docs\n\nCheck out the [HTTP API documentation](https://elevenlabs.io/docs/api-reference).\n\n## Install\n\n```bash\npip install elevenlabs\n```\n\n## Usage\n\n### Main Models\n\n1. **Eleven Multilingual v2** (`eleven_multilingual_v2`)\n\n    - Excels in stability, language diversity, and accent accuracy\n    - Supports 29 languages\n    - Recommended for most use cases\n\n2. **Eleven Flash v2.5** (`eleven_flash_v2_5`)\n\n    - Ultra-low latency\n    - Supports 32 languages\n    - Faster model, 50% lower price per character\n\n2. **Eleven Turbo v2.5** (`eleven_turbo_v2_5`)\n\n    - Good balance of quality and latency\n    - Ideal for developer use cases where speed is crucial\n    - Supports 32 languages\n\nFor more detailed information about these models and others, visit the [ElevenLabs Models documentation](https://elevenlabs.io/docs/models).\n\n```py\nfrom dotenv import load_dotenv\nfrom elevenlabs.client import ElevenLabs\nfrom elevenlabs.play import play\n\nload_dotenv()\n\nclient = ElevenLabs()\n\naudio = client.text_to_speech.convert(\n    text=\"The first move is what sets everything in motion.\",\n    voice_id=\"JBFqnCBsd6RMkjVDRZzb\",\n    model_id=\"eleven_multilingual_v2\",\n    output_format=\"mp3_44100_128\",\n)\n\nplay(audio)\n```\n\n\u003cdetails\u003e \u003csummary\u003e Play \u003c/summary\u003e\n\n🎧 **Try it out!** Want to hear our voices in action? Visit the [ElevenLabs Voice Lab](https://elevenlabs.io/voice-lab) to experiment with different voices, languages, and settings.\n\n\u003c/details\u003e\n\n## Voices\n\nList all your available voices with `voices()`.\n\n```py\nfrom elevenlabs.client import ElevenLabs\n\nclient = ElevenLabs(\n  api_key=\"YOUR_API_KEY\",\n)\n\nresponse = client.voices.search()\nprint(response.voices)\n```\n\nFor information about the structure of the voices output, please refer to the [official ElevenLabs API documentation for Get Voices](https://elevenlabs.io/docs/api-reference/get-voices).\n\nBuild a voice object with custom settings to personalize the voice style, or call\n`client.voices.get_settings(\"your-voice-id\")` to get the default settings for the voice.\n\n\u003c/details\u003e\n\n## Clone Voice\n\nClone your voice in an instant. Note that voice cloning requires an API key, see below.\n\n```py\nfrom elevenlabs.client import ElevenLabs\nfrom elevenlabs.play import play\n\nclient = ElevenLabs(\n  api_key=\"YOUR_API_KEY\",\n)\n\nvoice = client.voices.ivc.create(\n    name=\"Alex\",\n    description=\"An old American male voice with a slight hoarseness in his throat. Perfect for news\", # Optional\n    files=[\"./sample_0.mp3\", \"./sample_1.mp3\", \"./sample_2.mp3\"],\n)\n```\n\n## Streaming\n\nStream audio in real-time, as it's being generated.\n\n```py\nfrom elevenlabs import stream\nfrom elevenlabs.client import ElevenLabs\n\nclient = ElevenLabs()\n\naudio_stream = client.text_to_speech.stream(\n    text=\"This is a test\",\n    voice_id=\"JBFqnCBsd6RMkjVDRZzb\",\n    model_id=\"eleven_multilingual_v2\"\n)\n\n# option 1: play the streamed audio locally\nstream(audio_stream)\n\n# option 2: process the audio bytes manually\nfor chunk in audio_stream:\n    if isinstance(chunk, bytes):\n        print(chunk)\n\n```\n\n## Async Client\n\nUse `AsyncElevenLabs` if you want to make API calls asynchronously.\n\n```python\nimport asyncio\n\nfrom elevenlabs.client import AsyncElevenLabs\n\neleven = AsyncElevenLabs(\n  api_key=\"MY_API_KEY\"\n)\n\nasync def print_models() -\u003e None:\n    models = await eleven.models.list()\n    print(models)\n\nasyncio.run(print_models())\n```\n\n## Conversational AI\n\nBuild interactive AI agents with real-time audio capabilities using ElevenLabs Conversational AI.\n\n### Basic Usage\n\n```python\nfrom elevenlabs.client import ElevenLabs\nfrom elevenlabs.conversational_ai.conversation import Conversation, ClientTools\nfrom elevenlabs.conversational_ai.default_audio_interface import DefaultAudioInterface\n\nclient = ElevenLabs(api_key=\"YOUR_API_KEY\")\n\n# Create audio interface for real-time audio input/output\naudio_interface = DefaultAudioInterface()\n\n# Create conversation\nconversation = Conversation(\n    client=client,\n    agent_id=\"your-agent-id\",\n    requires_auth=True,\n    audio_interface=audio_interface,\n)\n\n# Start the conversation\nconversation.start_session()\n\n# The conversation runs in background until you call:\nconversation.end_session()\n```\n\n### Custom Event Loop Support\n\nFor advanced use cases involving context propagation, resource reuse, or specific event loop management, `ClientTools` supports custom asyncio event loops:\n\n```python\nimport asyncio\nfrom elevenlabs.conversational_ai.conversation import ClientTools\n\nasync def main():\n    # Get the current event loop\n    custom_loop = asyncio.get_running_loop()\n\n    # Create ClientTools with custom loop to prevent \"different event loop\" errors\n    client_tools = ClientTools(loop=custom_loop)\n\n    # Register your tools\n    async def get_weather(params):\n        location = params.get(\"location\", \"Unknown\")\n        # Your async logic here\n        return f\"Weather in {location}: Sunny, 72°F\"\n\n    client_tools.register(\"get_weather\", get_weather, is_async=True)\n\n    # Use with conversation\n    conversation = Conversation(\n        client=client,\n        agent_id=\"your-agent-id\",\n        requires_auth=True,\n        audio_interface=audio_interface,\n        client_tools=client_tools\n    )\n\nasyncio.run(main())\n```\n\n**Benefits of Custom Event Loop:**\n- **Context Propagation**: Maintain request-scoped state across async operations\n- **Resource Reuse**: Share existing async resources like HTTP sessions or database pools\n- **Loop Management**: Prevent \"Task got Future attached to a different event loop\" errors\n- **Performance**: Better control over async task scheduling and execution\n\n**Important:** When using a custom loop, you're responsible for its lifecycle\nDon't close the loop while ClientTools are still using it.\n\n### Tool Registration\n\nRegister custom tools that the AI agent can call during conversations:\n\n```python\nclient_tools = ClientTools()\n\n# Sync tool\ndef calculate_sum(params):\n    numbers = params.get(\"numbers\", [])\n    return sum(numbers)\n\n# Async tool\nasync def fetch_data(params):\n    url = params.get(\"url\")\n    # Your async HTTP request logic\n    return {\"data\": \"fetched\"}\n\nclient_tools.register(\"calculate_sum\", calculate_sum, is_async=False)\nclient_tools.register(\"fetch_data\", fetch_data, is_async=True)\n```\n\n## Languages Supported\n\nExplore [all models \u0026 languages](https://elevenlabs.io/docs/models).\n\n## Contributing\n\nWhile 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!\n\nOn the other hand, contributions to the README are always very welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felevenlabs%2Felevenlabs-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felevenlabs%2Felevenlabs-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felevenlabs%2Felevenlabs-python/lists"}