@@ -41,18 +41,21 @@ pip install elevenlabs
4141For more detailed information about these models and others, visit the [ ElevenLabs Models documentation] ( https://elevenlabs.io/docs/speech-synthesis/models ) .
4242
4343``` py
44- from elevenlabs import play
44+ from dotenv import load_dotenv
4545from elevenlabs.client import ElevenLabs
46+ from elevenlabs import play
4647
47- client = ElevenLabs(
48- api_key = " YOUR_API_KEY" , # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
49- )
48+ load_dotenv()
5049
51- audio = client.generate(
52- text = " Hello! 你好! Hola! नमस्ते! Bonjour! こんにちは! مرحبا! 안녕하세요! Ciao! Cześć! Привіт! வணக்கம்!" ,
53- voice = " Brian" ,
54- model = " eleven_multilingual_v2"
50+ client = ElevenLabs()
51+
52+ audio = client.text_to_speech.convert(
53+ text = " The first move is what sets everything in motion." ,
54+ voice_id = " JBFqnCBsd6RMkjVDRZzb" ,
55+ model_id = " eleven_multilingual_v2" ,
56+ output_format = " mp3_44100_128" ,
5557)
58+
5659play(audio)
5760```
5861
@@ -70,11 +73,10 @@ List all your available voices with `voices()`.
7073from elevenlabs.client import ElevenLabs
7174
7275client = ElevenLabs(
73- api_key = " YOUR_API_KEY" , # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
76+ api_key = " YOUR_API_KEY" ,
7477)
7578
7679response = client.voices.get_all()
77- audio = client.generate(text = " Hello there!" , voice = response.voices[0 ])
7880print (response.voices)
7981```
8082
@@ -83,25 +85,6 @@ For information about the structure of the voices output, please refer to the [o
8385Build a voice object with custom settings to personalize the voice style, or call
8486` client.voices.get_settings("your-voice-id") ` to get the default settings for the voice.
8587
86- ``` py
87- from elevenlabs import Voice, VoiceSettings, play
88- from elevenlabs.client import ElevenLabs
89-
90- client = ElevenLabs(
91- api_key = " YOUR_API_KEY" , # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
92- )
93-
94- audio = client.generate(
95- text = " Hello! My name is Brian." ,
96- voice = Voice(
97- voice_id = ' nPczCjzI2devNBz1zQrb' ,
98- settings = VoiceSettings(stability = 0.71 , similarity_boost = 0.5 , style = 0.0 , use_speaker_boost = True )
99- )
100- )
101-
102- play(audio)
103- ```
104-
10588</details >
10689
10790## Clone Voice
@@ -113,42 +96,41 @@ from elevenlabs.client import ElevenLabs
11396from elevenlabs import play
11497
11598client = ElevenLabs(
116- api_key = " YOUR_API_KEY" , # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
99+ api_key = " YOUR_API_KEY" , # Defaults ELEVENLABS_API_KEY
117100)
118101
119102voice = client.clone(
120103 name = " Alex" ,
121104 description = " An old American male voice with a slight hoarseness in his throat. Perfect for news" , # Optional
122105 files = [" ./sample_0.mp3" , " ./sample_1.mp3" , " ./sample_2.mp3" ],
123106)
124-
125- audio = client.generate(text = " Hi! I'm a cloned voice!" , voice = voice)
126-
127- play(audio)
128107```
129108
130109## 🚿 Streaming
131110
132111Stream audio in real-time, as it's being generated.
133112
134113``` py
135- from elevenlabs.client import ElevenLabs
136114from elevenlabs import stream
115+ from elevenlabs.client import ElevenLabs
137116
138- client = ElevenLabs(
139- api_key = " YOUR_API_KEY" , # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
140- )
117+ client = ElevenLabs()
141118
142- audio_stream = client.generate(
143- text = " This is a... streaming voice!!" ,
144- stream = True
119+ audio_stream = client.text_to_speech.convert_as_stream(
120+ text = " This is a test" ,
121+ voice_id = " JBFqnCBsd6RMkjVDRZzb" ,
122+ model_id = " eleven_multilingual_v2"
145123)
146124
125+ # option 1: play the streamed audio locally
147126stream(audio_stream)
148- ```
149127
150- Note that ` generate ` is a helper function. If you'd like to access
151- the raw method, simply use ` client.text_to_speech.convert_as_stream ` .
128+ # option 2: process the audio bytes manually
129+ for chunk in audio_stream:
130+ if isinstance (chunk, bytes ):
131+ print (chunk)
132+
133+ ```
152134
153135### Input streaming
154136
@@ -159,7 +141,7 @@ from elevenlabs.client import ElevenLabs
159141from elevenlabs import stream
160142
161143client = ElevenLabs(
162- api_key = " YOUR_API_KEY" , # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
144+ api_key = " YOUR_API_KEY" , # Defaults to ELEVENLABS_API_KEY
163145)
164146
165147def text_stream ():
@@ -176,9 +158,6 @@ audio_stream = client.generate(
176158stream(audio_stream)
177159```
178160
179- Note that ` generate ` is a helper function. If you'd like to access
180- the raw method, simply use ` client.text_to_speech.convert_realtime ` .
181-
182161## Async Client
183162
184163Use ` AsyncElevenLabs ` if you want to make API calls asynchronously.
@@ -189,7 +168,7 @@ import asyncio
189168from elevenlabs.client import AsyncElevenLabs
190169
191170eleven = AsyncElevenLabs(
192- api_key = " MY_API_KEY" # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
171+ api_key = " MY_API_KEY" # Defaults to ELEVENLABS_API_KEY
193172)
194173
195174async def print_models () -> None :
0 commit comments