@@ -41,18 +41,21 @@ pip install elevenlabs
41
41
For more detailed information about these models and others, visit the [ ElevenLabs Models documentation] ( https://elevenlabs.io/docs/speech-synthesis/models ) .
42
42
43
43
``` py
44
- from elevenlabs import play
44
+ from dotenv import load_dotenv
45
45
from elevenlabs.client import ElevenLabs
46
+ from elevenlabs import play
46
47
47
- client = ElevenLabs(
48
- api_key = " YOUR_API_KEY" , # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
49
- )
48
+ load_dotenv()
50
49
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" ,
55
57
)
58
+
56
59
play(audio)
57
60
```
58
61
@@ -70,11 +73,10 @@ List all your available voices with `voices()`.
70
73
from elevenlabs.client import ElevenLabs
71
74
72
75
client = ElevenLabs(
73
- api_key = " YOUR_API_KEY" , # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
76
+ api_key = " YOUR_API_KEY" ,
74
77
)
75
78
76
79
response = client.voices.get_all()
77
- audio = client.generate(text = " Hello there!" , voice = response.voices[0 ])
78
80
print (response.voices)
79
81
```
80
82
@@ -83,25 +85,6 @@ For information about the structure of the voices output, please refer to the [o
83
85
Build a voice object with custom settings to personalize the voice style, or call
84
86
` client.voices.get_settings("your-voice-id") ` to get the default settings for the voice.
85
87
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
-
105
88
</details >
106
89
107
90
## Clone Voice
@@ -113,42 +96,41 @@ from elevenlabs.client import ElevenLabs
113
96
from elevenlabs import play
114
97
115
98
client = 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
117
100
)
118
101
119
102
voice = client.clone(
120
103
name = " Alex" ,
121
104
description = " An old American male voice with a slight hoarseness in his throat. Perfect for news" , # Optional
122
105
files = [" ./sample_0.mp3" , " ./sample_1.mp3" , " ./sample_2.mp3" ],
123
106
)
124
-
125
- audio = client.generate(text = " Hi! I'm a cloned voice!" , voice = voice)
126
-
127
- play(audio)
128
107
```
129
108
130
109
## 🚿 Streaming
131
110
132
111
Stream audio in real-time, as it's being generated.
133
112
134
113
``` py
135
- from elevenlabs.client import ElevenLabs
136
114
from elevenlabs import stream
115
+ from elevenlabs.client import ElevenLabs
137
116
138
- client = ElevenLabs(
139
- api_key = " YOUR_API_KEY" , # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
140
- )
117
+ client = ElevenLabs()
141
118
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"
145
123
)
146
124
125
+ # option 1: play the streamed audio locally
147
126
stream(audio_stream)
148
- ```
149
127
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
+ ```
152
134
153
135
### Input streaming
154
136
@@ -159,7 +141,7 @@ from elevenlabs.client import ElevenLabs
159
141
from elevenlabs import stream
160
142
161
143
client = 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
163
145
)
164
146
165
147
def text_stream ():
@@ -176,9 +158,6 @@ audio_stream = client.generate(
176
158
stream(audio_stream)
177
159
```
178
160
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
-
182
161
## Async Client
183
162
184
163
Use ` AsyncElevenLabs ` if you want to make API calls asynchronously.
@@ -189,7 +168,7 @@ import asyncio
189
168
from elevenlabs.client import AsyncElevenLabs
190
169
191
170
eleven = 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
193
172
)
194
173
195
174
async def print_models () -> None :
0 commit comments