Skip to content

The official Python API for ElevenLabs text-to-speech.

Notifications You must be signed in to change notification settings

gvariable/elevenlabs-python

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

65 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

LOGO

Discord Twitter PyPI - Python Version Downloads

The official Python API for ElevenLabs text-to-speech software. Eleven brings the most compelling, rich and lifelike voices to creators and developers in just a few lines of code.

โš™๏ธ Install

pip install elevenlabs

๐Ÿ—ฃ๏ธ Usage

Open in Spaces Open In Colab

from elevenlabs import generate, play

audio = generate(
  text="Hi! My name is Bella, nice to meet you!",
  voice="Bella",
  model="eleven_monolingual_v1"
)

play(audio)
Play

Don't forget to unmute the player!

Adam

Adam.webm

Antoni

Antoni.webm

Arnold

Arnold.webm

Bella

Bella.webm

Domi

Domi.webm

Elli

Elli.webm

Josh

Josh.webm

Rachel

Rachel.webm

Sam

Sam.webm

๐ŸŒŽ Multilingual

The eleven_multilingual_v1 model supports multiple languages, including English, German, Polish, Spanish, Italian, French, Portuguese, and Hindi.

from elevenlabs import generate, play

audio = generate(
    text="ยกHola! Mi nombre es Arnold, encantado de conocerte!",
    voice="Arnold",
    model='eleven_multilingual_v1'
)

play(audio)
Play

Don't forget to unmute the player!

hola.webm

๐Ÿ—ฃ๏ธ Voices

List all your available voices with voices().

from elevenlabs import voices, generate

voices = voices()

audio = generate(text="Hello there!", voice=voices[0])

print(voices)
Show output
Voices(
    voices=[
        Voice(
            voice_id='21m00Tcm4TlvDq8ikWAM',
            name='Rachel',
            category='premade',
            settings=VoiceSettings(stability=0.75, similarity_boost=0.75)
        ),
        Voice(
            voice_id='AZnzlk1XvdvUeBnXmlld',
            name='Domi',
            category='premade',
            settings=VoiceSettings(stability=0.1, similarity_boost=0.75)
        ),
        Voice(
            voice_id='EXAVITQu4vr4xnSDxMaL',
            name='Bella',
            category='premade',
            settings=VoiceSettings(stability=0.245, similarity_boost=0.75)
        ),
        Voice(
            voice_id='ErXwobaYiN019PkySvjV',
            name='Antoni',
            category='premade',
            settings=VoiceSettings(stability=0.195, similarity_boost=0.75)
        ),
        Voice(
            voice_id='MF3mGyEYCl7XYWbV9V6O',
            name='Elli',
            category='premade',
            settings=VoiceSettings(stability=0.755, similarity_boost=0.75)
        ),
        Voice(
            voice_id='TxGEqnHWrfWFTfGW9XjX',
            name='Josh',
            category='premade',
            settings=VoiceSettings(stability=0.15, similarity_boost=0.51)
        ),
        Voice(
            voice_id='VR6AewLTigWG4xSOukaG',
            name='Arnold',
            category='premade',
            settings=VoiceSettings(stability=0.15, similarity_boost=0.75)
        ),
        Voice(
            voice_id='pNInz6obpgDQGcFmaJgB',
            name='Adam',
            category='premade',
            settings=VoiceSettings(stability=0.2, similarity_boost=0.75)
        ),
        Voice(
            voice_id='yoZ06aMxZJJ28mfd3POQ',
            name='Sam',
            category='premade',
            settings=VoiceSettings(stability=0.25, similarity_boost=0.75)
        ),
        Voice(
            voice_id='3KehPe3gxEYqOFSGDzGM',
            name='test',
            category='cloned',
            settings=VoiceSettings(stability=0.75, similarity_boost=0.75)
        ),
        Voice(
            voice_id='duorpit9NOULscUJ2OAp',
            name='test',
            category='cloned',
            settings=VoiceSettings(stability=0.75, similarity_boost=0.75)
        ),
        Voice(
            voice_id='h2rNV1Iql95D2QSSuvLY',
            name='test',
            category='cloned',
            settings=VoiceSettings(stability=0.75, similarity_boost=0.75)
        )
    ]
)

Clone Voice

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

from elevenlabs import clone, generate, play

voice = 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 = generate(text="Hi! I'm a cloned voice!", voice=voice)

play(audio)

๐Ÿšฟ Streaming

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

from elevenlabs import generate, stream

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

stream(audio_stream)

Input streaming

Stream text chunks into audio as it's being generated. Note chunks must end with a space or punctuation (" ", ".", "?", "!").

from elevenlabs import generate, stream

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

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

stream(audio_stream)

๐Ÿ”‘ API Key

The basic API has a limited number of characters. To increase this limit, you can get a free API key from Elevenlabs (step-by-step guide) and set is as environment variable ELEVEN_API_KEY. Alternatively you can provide the api_key string argument to the generate function, or set it globally in code with:

from elevenlabs import set_api_key
set_api_key("<YOUR_API_KEY>")

๐Ÿ“– API & Docs

Learn more about the Python API, or check out the HTTP API documentation.

About

The official Python API for ElevenLabs text-to-speech.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%