Skip to content

Commit b1bb15c

Browse files
fix: generate -> raw methods
1 parent 5f1a1ad commit b1bb15c

File tree

1 file changed

+25
-46
lines changed

1 file changed

+25
-46
lines changed

README.md

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,21 @@ pip install elevenlabs
4141
For 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
4545
from 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+
5659
play(audio)
5760
```
5861

@@ -70,11 +73,10 @@ List all your available voices with `voices()`.
7073
from elevenlabs.client import ElevenLabs
7174

7275
client = ElevenLabs(
73-
api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY or ELEVENLABS_API_KEY
76+
api_key="YOUR_API_KEY",
7477
)
7578

7679
response = client.voices.get_all()
77-
audio = client.generate(text="Hello there!", voice=response.voices[0])
7880
print(response.voices)
7981
```
8082

@@ -83,25 +85,6 @@ For information about the structure of the voices output, please refer to the [o
8385
Build 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
@@ -121,34 +104,33 @@ voice = client.clone(
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

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

134113
```py
135-
from elevenlabs.client import ElevenLabs
136114
from 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
147126
stream(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

@@ -176,9 +158,6 @@ audio_stream = client.generate(
176158
stream(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

184163
Use `AsyncElevenLabs` if you want to make API calls asynchronously.

0 commit comments

Comments
 (0)