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