Spaces:
Runtime error
Runtime error
File size: 1,102 Bytes
a9922ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
from elevenlabs.client import ElevenLabs
import gradio as gr
import os
from elevenlabs import play
client = ElevenLabs(
# api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY
)
female_voice = "nDJIICjR9zfJExIFeSCN"
male_voice = "1m3E2x7boso3AU9J3woJ"
def talk():
# Define the dialogue text and assign different voices
dialogue = [
{"text": "Hello! How are you today?", "voice": female_voice},
{"text": "I'm doing well, thank you! How about you?", "voice": male_voice},
{"text": "I'm great, thanks for asking!", "voice": female_voice},
]
# Generate and play the dialogue
for line in dialogue:
audio = client.generate(
text=line["text"],
voice=line["voice"],
model="eleven_monolingual_v1",
)
# play(audio)
yield audio
def speak():
clips = [b"".join(audio) for audio in talk()]
return b"".join(clips)
def get_interface():
with gr.Blocks() as blocks:
gr.Audio(value=speak)
return blocks
if __name__ == '__main__':
demo = get_interface()
demo.launch()
|