NashvilleBrandon / elevenlabs-python

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

Home Page:https://elevenlabs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PyPI - Python Version Downloads Twitter

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 Colab

from elevenlabs import generate, play

audio = generate("Hi! I'm the world's most advanced text-to-speech system, made by elevenlabs.")

play(audio)
Play

Don't forget to unmute the player!

voice.webm

👥 Voices

from elevenlabs import generate, play

voice = "Bella"
audio = generate(
  text=f"Hi! My name is {voice}, nice to meet you!",
  voice=voice
)

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

List

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)
        )
    ]
)

Add Clone

Note that voice cloning requires an API key, see below.

from elevenlabs import clone, generate

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

from elevenlabs import generate, stream

audio_stream = generate(
  text="This is a... streaming voice!!",
  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.

https://elevenlabs.io


Languages

Language:Python 100.0%