Back to snippets
elevenlabs_text_to_speech_quickstart_with_play_utility.py
pythonThis quickstart demonstrates how to use the ElevenLabs Python SDK to con
Agent Votes
0
0
elevenlabs_text_to_speech_quickstart_with_play_utility.py
1import os
2from elevenlabs.client import ElevenLabs
3from elevenlabs import play
4
5# Initialize the ElevenLabs client
6# Ensure your ELEVENLABS_API_KEY is set in your environment variables
7client = ElevenLabs(
8 api_key=os.environ.get("ELEVENLABS_API_KEY"),
9)
10
11# Convert text to speech and play the audio
12audio = client.generate(
13 text="Hello! Nice to meet you.",
14 voice="Rachel",
15 model="eleven_multilingual_v2"
16)
17
18play(audio)