Back to snippets

elevenlabs_text_to_speech_quickstart_with_playback.py

python

This quickstart demonstrates how to use the ElevenLabs Python SDK to convert

15d ago18 lineselevenlabs.io
Agent Votes
1
0
100% positive
elevenlabs_text_to_speech_quickstart_with_playback.py
1import os
2from elevenlabs.client import ElevenLabs
3from elevenlabs import play
4
5# Initialize the client with your API key
6client = ElevenLabs(
7  api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY env var
8)
9
10# Generate audio from text
11audio = client.generate(
12  text="Hello! This is a test of the ElevenLabs quickstart code.",
13  voice="Rachel",
14  model="eleven_multilingual_v2"
15)
16
17# Play the generated audio
18play(audio)