elevenlabs


Nameelevenlabs JSON
Version 1.2.2 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2024-05-12 02:06:56
maintainerNone
docs_urlNone
authorNone
requires_python<4.0,>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ElevenLabs Python Library

![LOGO](https://github.com/elevenlabs/elevenlabs-python/assets/12028621/21267d89-5e82-4e7e-9c81-caf30b237683)

[![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)
[![Discord](https://badgen.net/badge/black/ElevenLabs/icon?icon=discord&label)](https://discord.gg/elevenlabs)
[![Twitter](https://badgen.net/badge/black/elevenlabsio/icon?icon=twitter&label)](https://twitter.com/elevenlabsio)
[![PyPI - Python Version](https://img.shields.io/pypi/v/elevenlabs?style=flat&colorA=black&colorB=black)](https://pypi.org/project/elevenlabs/)
[![Downloads](https://static.pepy.tech/personalized-badge/elevenlabs?period=total&units=international_system&left_color=black&right_color=black&left_text=Downloads)](https://pepy.tech/project/elevenlabs)

The official Python API for [ElevenLabs](https://elevenlabs.io/) [text-to-speech software.](https://elevenlabs.io/text-to-speech) Eleven 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](https://elevenlabs.io/docs/api-reference).

## ⚙️ Install

```bash
pip install elevenlabs
```

## v0.x to v1.x Migration Guide
> The SDK was rewritten in v1 and is now programmatically generated from our OpenAPI spec. As part of this release 
> there are some breaking changes. 


### Client Instantiation
The SDK now exports a client class that you must instantiate to call various
endpoints in our API. 

```python
from elevenlabs.client import ElevenLabs

client = ElevenLabs(
  api_key="..." # Defaults to ELEVEN_API_KEY
)
```
As part of this change, there is no longer a `set_api_key` and `get_api_key` method exported. 

### HTTPX
The SDK now uses httpx under the hood. This allows us to export an async client in addition to 
a synchronous client. Note that you can pass in your own httpx client as well. 

```python
from elevenlabs.client import AsyncElevenLabs

client = AsyncElevenLabs(
  api_key="...",  # Defaults to ELEVEN_API_KEY
  httpx_client=httpx.AsyncClient(...)
)
```

### Removing Static Methods
There are no longer static methods exposed directly on objects. For example, 
instead of `Models.from_api()` you can now do `client.models.get_all()`. 

The renames are specified below: 

  `User.from_api()` -> `client.users.get()`

  `Models.from_api()` -> `client.models.get_all()`

  `Voices.from_api()` -> `client.voices.get_all()` 

  `History.from_api()` -> `client.history.get_all()` 


### Exported functions
The SDK no longer exports top level functions `generate`, `clone`, and `voices`. Instead, 
everything is now directly attached to the client instance. 

#### `generate` -> `client.generate`

The generate method is a helper function that makes it easier to consume the 
text-to-speech APIs. If you'd rather access the raw APIs, simply use `client.text_to_speech`. 

#### `clone` -> `client.clone`

The clone method is a helper function that wraps the voices add and 
get APIs. If you'd rather access the raw APIs, simply use `client.voices.add()`. 

#### `voice` -> `client.voices.get_all()` 

To get all your voices, use `client.voices.get_all()`. 

#### `play`, `stream` and `save`

The SDK continues to export the `play`, `stream` and `save` methods. Under the hood, these methods
use ffmpeg and mpv to play audio streams. 

```python
from elevenlabs import play, stream, save

# plays audio using ffmpeg
play(audio)
# streams audio using mpv
stream(audio)
# saves audio to file
save(audio, "my-file.mp3")
```


## 🗣️ Usage
[![Open in Spaces](https://img.shields.io/badge/🤗-Open%20in%20Spaces-blue.svg)](https://huggingface.co/spaces/elevenlabs/tts)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/flavioschneider/49468d728a816c6538fd2f56b3b50b96/elevenlabs-python.ipynb)

We support two main models: the newest `eleven_multilingual_v2`, a single foundational model supporting 29 languages including English, Chinese, Spanish, Hindi, Portuguese, French, German, Japanese, Arabic, Korean, Indonesian, Italian, Dutch, Turkish, Polish, Swedish, Filipino, Malay, Russian, Romanian, Ukrainian, Greek, Czech, Danish, Finnish, Bulgarian, Croatian, Slovak, and Tamil; and `eleven_monolingual_v1`, a low-latency model specifically trained for English speech.

```py
from elevenlabs import play
from elevenlabs.client import ElevenLabs

client = ElevenLabs(
  api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY
)

audio = client.generate(
  text="Hello! 你好! Hola! नमस्ते! Bonjour! こんにちは! مرحبا! 안녕하세요! Ciao! Cześć! Привіт! வணக்கம்!",
  voice="Rachel",
  model="eleven_multilingual_v2"
)
play(audio)
```

<details> <summary> Play </summary>

<i> Don't forget to unmute the player! </i>

[audio (3).webm](https://github.com/elevenlabs/elevenlabs-python/assets/12028621/778fd3ed-0a3a-4d66-8f73-faee099dfdd6)

</details>

## 🗣️ Voices

List all your available voices with `voices()`.
```py
from elevenlabs.client import ElevenLabs

client = ElevenLabs(
  api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY
)

response = client.voices.get_all()
audio = client.generate(text="Hello there!", voice=response.voices[0])
print(response.voices)
```

<details> <summary> Show output </summary>

```py
[
  Voice(
      voice_id='21m00Tcm4TlvDq8ikWAM',
      name='Rachel',
      category='premade',
      settings=None,
  ),
  Voice(
      voice_id='AZnzlk1XvdvUeBnXmlld',
      name='Domi',
      category='premade',
      settings=None,
  ),
]
```

</details>

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.

```py
from elevenlabs import Voice, VoiceSettings, play
from elevenlabs.client import ElevenLabs

client = ElevenLabs(
  api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY
)

audio = client.generate(
    text="Hello! My name is Bella.",
    voice=Voice(
        voice_id='EXAVITQu4vr4xnSDxMaL',
        settings=VoiceSettings(stability=0.71, similarity_boost=0.5, style=0.0, use_speaker_boost=True)
    )
)

play(audio)
```

</details>

## Clone Voice

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

```py
from elevenlabs.client import ElevenLabs
from elevenlabs import play

client = ElevenLabs(
  api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY
)

voice = client.clone(
    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"],
)

audio = client.generate(text="Hi! I'm a cloned voice!", voice=voice)

play(audio)
```

## 🚿 Streaming

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

```py
from elevenlabs.client import ElevenLabs
from elevenlabs import stream

client = ElevenLabs(
  api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY
)

audio_stream = client.generate(
  text="This is a... streaming voice!!",
  stream=True
)

stream(audio_stream)
```

Note that `generate` is a helper function. If you'd like to access
the raw method, simply use `client.text_to_speech.convert_as_stream`. 

### Input streaming
Stream text chunks into audio as it's being generated, with <1s latency. Note: if chunks don't end with space or punctuation (" ", ".", "?", "!"), the stream will wait for more text.
```py
from elevenlabs.client import ElevenLabs
from elevenlabs import stream

client = ElevenLabs(
  api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY
)

def text_stream():
    yield "Hi there, I'm Eleven "
    yield "I'm a text to speech API "

audio_stream = client.generate(
    text=text_stream(),
    voice="Nicole",
    model="eleven_monolingual_v1",
    stream=True
)

stream(audio_stream)
```

Note that `generate` is a helper function. If you'd like to access
the raw method, simply use `client.text_to_speech.convert_realtime`. 


## Async Client 
Use `AsyncElevenLabs` if you want to make API calls asynchronously. 

```python
import asyncio

from elevenlabs.client import AsyncElevenLabs

eleven = AsyncElevenLabs(
  api_key="MY_API_KEY" # Defaulsts to ELEVEN_API_KEY
)

async def print_models() -> None:
    models = await eleven.models.get_all()
    print(models)

asyncio.run(print_models())
```

## Elevenlabs module
All of the ElevenLabs models are nested within the elevenlabs module. 

![Alt text](assets/module.png)

## Languages Supported

We support 29 languages and 100+ accents. Explore [all languages](https://elevenlabs.io/languages).

<img src="https://github.com/elevenlabs/elevenlabs-js/blob/main/assets/languages.png" width="900">

## 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!

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "elevenlabs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/ef/dd/eb488a1e14e680e71652d392140d37e50581f2511ae52dbef741ef653861/elevenlabs-1.2.2.tar.gz",
    "platform": null,
    "description": "# 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&label)](https://discord.gg/elevenlabs)\n[![Twitter](https://badgen.net/badge/black/elevenlabsio/icon?icon=twitter&label)](https://twitter.com/elevenlabsio)\n[![PyPI - Python Version](https://img.shields.io/pypi/v/elevenlabs?style=flat&colorA=black&colorB=black)](https://pypi.org/project/elevenlabs/)\n[![Downloads](https://static.pepy.tech/personalized-badge/elevenlabs?period=total&units=international_system&left_color=black&right_color=black&left_text=Downloads)](https://pepy.tech/project/elevenlabs)\n\nThe official Python API for [ElevenLabs](https://elevenlabs.io/) [text-to-speech software.](https://elevenlabs.io/text-to-speech) Eleven brings the most compelling, rich and lifelike voices to creators and developers in just a few lines of code.\n\n## \ud83d\udcd6 API & Docs\n\nCheck out the [HTTP API documentation](https://elevenlabs.io/docs/api-reference).\n\n## \u2699\ufe0f Install\n\n```bash\npip install elevenlabs\n```\n\n## v0.x to v1.x Migration Guide\n> The SDK was rewritten in v1 and is now programmatically generated from our OpenAPI spec. As part of this release \n> there are some breaking changes. \n\n\n### Client Instantiation\nThe SDK now exports a client class that you must instantiate to call various\nendpoints in our API. \n\n```python\nfrom elevenlabs.client import ElevenLabs\n\nclient = ElevenLabs(\n  api_key=\"...\" # Defaults to ELEVEN_API_KEY\n)\n```\nAs part of this change, there is no longer a `set_api_key` and `get_api_key` method exported. \n\n### HTTPX\nThe SDK now uses httpx under the hood. This allows us to export an async client in addition to \na synchronous client. Note that you can pass in your own httpx client as well. \n\n```python\nfrom elevenlabs.client import AsyncElevenLabs\n\nclient = AsyncElevenLabs(\n  api_key=\"...\",  # Defaults to ELEVEN_API_KEY\n  httpx_client=httpx.AsyncClient(...)\n)\n```\n\n### Removing Static Methods\nThere are no longer static methods exposed directly on objects. For example, \ninstead of `Models.from_api()` you can now do `client.models.get_all()`. \n\nThe renames are specified below: \n\n  `User.from_api()` -> `client.users.get()`\n\n  `Models.from_api()` -> `client.models.get_all()`\n\n  `Voices.from_api()` -> `client.voices.get_all()` \n\n  `History.from_api()` -> `client.history.get_all()` \n\n\n### Exported functions\nThe SDK no longer exports top level functions `generate`, `clone`, and `voices`. Instead, \neverything is now directly attached to the client instance. \n\n#### `generate` -> `client.generate`\n\nThe generate method is a helper function that makes it easier to consume the \ntext-to-speech APIs. If you'd rather access the raw APIs, simply use `client.text_to_speech`. \n\n#### `clone` -> `client.clone`\n\nThe clone method is a helper function that wraps the voices add and \nget APIs. If you'd rather access the raw APIs, simply use `client.voices.add()`. \n\n#### `voice` -> `client.voices.get_all()` \n\nTo get all your voices, use `client.voices.get_all()`. \n\n#### `play`, `stream` and `save`\n\nThe SDK continues to export the `play`, `stream` and `save` methods. Under the hood, these methods\nuse ffmpeg and mpv to play audio streams. \n\n```python\nfrom elevenlabs import play, stream, save\n\n# plays audio using ffmpeg\nplay(audio)\n# streams audio using mpv\nstream(audio)\n# saves audio to file\nsave(audio, \"my-file.mp3\")\n```\n\n\n## \ud83d\udde3\ufe0f Usage\n[![Open in Spaces](https://img.shields.io/badge/\ud83e\udd17-Open%20in%20Spaces-blue.svg)](https://huggingface.co/spaces/elevenlabs/tts)\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/flavioschneider/49468d728a816c6538fd2f56b3b50b96/elevenlabs-python.ipynb)\n\nWe support two main models: the newest `eleven_multilingual_v2`, a single foundational model supporting 29 languages including English, Chinese, Spanish, Hindi, Portuguese, French, German, Japanese, Arabic, Korean, Indonesian, Italian, Dutch, Turkish, Polish, Swedish, Filipino, Malay, Russian, Romanian, Ukrainian, Greek, Czech, Danish, Finnish, Bulgarian, Croatian, Slovak, and Tamil; and `eleven_monolingual_v1`, a low-latency model specifically trained for English speech.\n\n```py\nfrom elevenlabs import play\nfrom elevenlabs.client import ElevenLabs\n\nclient = ElevenLabs(\n  api_key=\"YOUR_API_KEY\", # Defaults to ELEVEN_API_KEY\n)\n\naudio = client.generate(\n  text=\"Hello! \u4f60\u597d! Hola! \u0928\u092e\u0938\u094d\u0924\u0947! Bonjour! \u3053\u3093\u306b\u3061\u306f! \u0645\u0631\u062d\u0628\u0627! \uc548\ub155\ud558\uc138\uc694! Ciao! Cze\u015b\u0107! \u041f\u0440\u0438\u0432\u0456\u0442! \u0bb5\u0ba3\u0b95\u0bcd\u0b95\u0bae\u0bcd!\",\n  voice=\"Rachel\",\n  model=\"eleven_multilingual_v2\"\n)\nplay(audio)\n```\n\n<details> <summary> Play </summary>\n\n<i> Don't forget to unmute the player! </i>\n\n[audio (3).webm](https://github.com/elevenlabs/elevenlabs-python/assets/12028621/778fd3ed-0a3a-4d66-8f73-faee099dfdd6)\n\n</details>\n\n## \ud83d\udde3\ufe0f Voices\n\nList all your available voices with `voices()`.\n```py\nfrom elevenlabs.client import ElevenLabs\n\nclient = ElevenLabs(\n  api_key=\"YOUR_API_KEY\", # Defaults to ELEVEN_API_KEY\n)\n\nresponse = client.voices.get_all()\naudio = client.generate(text=\"Hello there!\", voice=response.voices[0])\nprint(response.voices)\n```\n\n<details> <summary> Show output </summary>\n\n```py\n[\n  Voice(\n      voice_id='21m00Tcm4TlvDq8ikWAM',\n      name='Rachel',\n      category='premade',\n      settings=None,\n  ),\n  Voice(\n      voice_id='AZnzlk1XvdvUeBnXmlld',\n      name='Domi',\n      category='premade',\n      settings=None,\n  ),\n]\n```\n\n</details>\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```py\nfrom elevenlabs import Voice, VoiceSettings, play\nfrom elevenlabs.client import ElevenLabs\n\nclient = ElevenLabs(\n  api_key=\"YOUR_API_KEY\", # Defaults to ELEVEN_API_KEY\n)\n\naudio = client.generate(\n    text=\"Hello! My name is Bella.\",\n    voice=Voice(\n        voice_id='EXAVITQu4vr4xnSDxMaL',\n        settings=VoiceSettings(stability=0.71, similarity_boost=0.5, style=0.0, use_speaker_boost=True)\n    )\n)\n\nplay(audio)\n```\n\n</details>\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 import play\n\nclient = ElevenLabs(\n  api_key=\"YOUR_API_KEY\", # Defaults to ELEVEN_API_KEY\n)\n\nvoice = client.clone(\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\naudio = client.generate(text=\"Hi! I'm a cloned voice!\", voice=voice)\n\nplay(audio)\n```\n\n## \ud83d\udebf Streaming\n\nStream audio in real-time, as it's being generated.\n\n```py\nfrom elevenlabs.client import ElevenLabs\nfrom elevenlabs import stream\n\nclient = ElevenLabs(\n  api_key=\"YOUR_API_KEY\", # Defaults to ELEVEN_API_KEY\n)\n\naudio_stream = client.generate(\n  text=\"This is a... streaming voice!!\",\n  stream=True\n)\n\nstream(audio_stream)\n```\n\nNote that `generate` is a helper function. If you'd like to access\nthe raw method, simply use `client.text_to_speech.convert_as_stream`. \n\n### Input streaming\nStream text chunks into audio as it's being generated, with <1s latency. Note: if chunks don't end with space or punctuation (\" \", \".\", \"?\", \"!\"), the stream will wait for more text.\n```py\nfrom elevenlabs.client import ElevenLabs\nfrom elevenlabs import stream\n\nclient = ElevenLabs(\n  api_key=\"YOUR_API_KEY\", # Defaults to ELEVEN_API_KEY\n)\n\ndef text_stream():\n    yield \"Hi there, I'm Eleven \"\n    yield \"I'm a text to speech API \"\n\naudio_stream = client.generate(\n    text=text_stream(),\n    voice=\"Nicole\",\n    model=\"eleven_monolingual_v1\",\n    stream=True\n)\n\nstream(audio_stream)\n```\n\nNote that `generate` is a helper function. If you'd like to access\nthe raw method, simply use `client.text_to_speech.convert_realtime`. \n\n\n## Async Client \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\" # Defaulsts to ELEVEN_API_KEY\n)\n\nasync def print_models() -> None:\n    models = await eleven.models.get_all()\n    print(models)\n\nasyncio.run(print_models())\n```\n\n## Elevenlabs module\nAll of the ElevenLabs models are nested within the elevenlabs module. \n\n![Alt text](assets/module.png)\n\n## Languages Supported\n\nWe support 29 languages and 100+ accents. Explore [all languages](https://elevenlabs.io/languages).\n\n<img src=\"https://github.com/elevenlabs/elevenlabs-js/blob/main/assets/languages.png\" width=\"900\">\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",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "1.2.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0b6535dc699c50c8fd7cf4b4178f98e2e230c93e8f8d6f02f1537d6c593978b9",
                "md5": "566e0d6db69b7b6a81c548c2116d3f87",
                "sha256": "60b92b0e2aabdfba93a43569f207f8a2ad397492519b8e11a2eebb32807ddefa"
            },
            "downloads": -1,
            "filename": "elevenlabs-1.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "566e0d6db69b7b6a81c548c2116d3f87",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 116459,
            "upload_time": "2024-05-12T02:06:54",
            "upload_time_iso_8601": "2024-05-12T02:06:54.652051Z",
            "url": "https://files.pythonhosted.org/packages/0b/65/35dc699c50c8fd7cf4b4178f98e2e230c93e8f8d6f02f1537d6c593978b9/elevenlabs-1.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "efddeb488a1e14e680e71652d392140d37e50581f2511ae52dbef741ef653861",
                "md5": "b87d7cd5441de3717c3c12935fc1324c",
                "sha256": "ebd02869b95602b8956874dd727981bb49ad16b9a3c2f5901193d838213694aa"
            },
            "downloads": -1,
            "filename": "elevenlabs-1.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b87d7cd5441de3717c3c12935fc1324c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 58471,
            "upload_time": "2024-05-12T02:06:56",
            "upload_time_iso_8601": "2024-05-12T02:06:56.659918Z",
            "url": "https://files.pythonhosted.org/packages/ef/dd/eb488a1e14e680e71652d392140d37e50581f2511ae52dbef741ef653861/elevenlabs-1.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-12 02:06:56",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "elevenlabs"
}
        
Elapsed time: 0.26174s