Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from edge_tts import Communicate
|
3 |
+
|
4 |
+
# Define a function to convert text to speech
|
5 |
+
async def text_to_speech(text):
|
6 |
+
communicate = Communicate()
|
7 |
+
await communicate.run(text, "output_audio.wav")
|
8 |
+
return "output_audio.wav"
|
9 |
+
|
10 |
+
# Create the Gradio interface
|
11 |
+
def create_interface():
|
12 |
+
# Define the Gradio interface components
|
13 |
+
with gr.Blocks() as demo:
|
14 |
+
gr.Markdown("# Text to Speech with Edge TTS")
|
15 |
+
|
16 |
+
text_input = gr.Textbox(label="Enter text here:")
|
17 |
+
output_audio = gr.Audio(label="Generated Speech")
|
18 |
+
|
19 |
+
def generate_speech(text):
|
20 |
+
# Run the text_to_speech function and get the output file path
|
21 |
+
import asyncio
|
22 |
+
output_path = asyncio.run(text_to_speech(text))
|
23 |
+
return output_path
|
24 |
+
|
25 |
+
generate_button = gr.Button("Generate Speech")
|
26 |
+
generate_button.click(generate_speech, inputs=text_input, outputs=output_audio)
|
27 |
+
|
28 |
+
return demo
|
29 |
+
|
30 |
+
# Create and launch the interface
|
31 |
+
demo = create_interface()
|
32 |
+
demo.launch()
|