Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
return "output_audio.wav"
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
generate_button = gr.Button("Generate Speech")
|
26 |
-
generate_button.click(generate_speech, inputs=text_input, outputs=output_audio)
|
27 |
|
28 |
-
|
29 |
|
30 |
-
# Create and launch the interface
|
31 |
-
demo = create_interface()
|
32 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import edge_tts
|
3 |
+
import asyncio
|
4 |
|
5 |
+
async def tts(text):
|
6 |
+
communicate = edge_tts.Communicate(text, 'en-US-JennyNeural')
|
7 |
+
result = await communicate.save("output.mp3")
|
8 |
+
return "output.mp3"
|
|
|
9 |
|
10 |
+
def tts_sync(text):
|
11 |
+
loop = asyncio.new_event_loop()
|
12 |
+
asyncio.set_event_loop(loop)
|
13 |
+
return loop.run_until_complete(tts(text))
|
14 |
+
|
15 |
+
with gr.Blocks() as demo:
|
16 |
+
gr.Markdown("## Text-to-Speech with Edge TTS")
|
17 |
+
|
18 |
+
with gr.Row():
|
19 |
+
with gr.Column():
|
20 |
+
text_input = gr.Textbox(label="Enter Text", placeholder="Type something here...")
|
21 |
+
submit_button = gr.Button("Convert to Speech")
|
22 |
+
|
23 |
+
with gr.Column():
|
24 |
+
audio_output = gr.Audio(label="Output Audio")
|
|
|
|
|
25 |
|
26 |
+
submit_button.click(fn=tts_sync, inputs=text_input, outputs=audio_output)
|
27 |
|
|
|
|
|
28 |
demo.launch()
|