Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import edge_tts
|
3 |
+
import asyncio
|
4 |
+
|
5 |
+
# TTS synthesis function
|
6 |
+
async def synthesize_tts(text, voice, rate, pitch):
|
7 |
+
tts = edge_tts.Communicate(text, voice, rate=f"{rate}%", pitch=f"{pitch}%")
|
8 |
+
output_file = "output.mp3"
|
9 |
+
await tts.save(output_file)
|
10 |
+
return output_file
|
11 |
+
|
12 |
+
# Gradio-compatible function for TTS
|
13 |
+
def generate_tts(text, voice, rate, pitch):
|
14 |
+
loop = asyncio.new_event_loop()
|
15 |
+
asyncio.set_event_loop(loop)
|
16 |
+
output_file = loop.run_until_complete(synthesize_tts(text, voice, rate, pitch))
|
17 |
+
return output_file
|
18 |
+
|
19 |
+
# API-friendly Gradio Interface
|
20 |
+
interface = gr.Interface(
|
21 |
+
fn=generate_tts,
|
22 |
+
inputs=[
|
23 |
+
gr.Textbox(label="Enter Text"),
|
24 |
+
gr.Dropdown(choices=["en-US-GuyNeural", "en-US-JennyNeural"], label="Voice"), # Add more voices
|
25 |
+
gr.Slider(-50, 50, value=0, label="Rate (%)"),
|
26 |
+
gr.Slider(-50, 50, value=0, label="Pitch (%)"),
|
27 |
+
],
|
28 |
+
outputs=gr.Audio(label="Generated Audio"),
|
29 |
+
allow_flagging="never", # Disables user feedback
|
30 |
+
live=True # Supports real-time processing
|
31 |
+
)
|
32 |
+
|
33 |
+
if __name__ == "__main__":
|
34 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|