Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +38 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import asyncio
|
| 3 |
+
import edge_tts
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# ✅ Async function to generate speech
|
| 7 |
+
async def generate_speech(text, voice):
|
| 8 |
+
communicate = edge_tts.Communicate(text, voice)
|
| 9 |
+
await communicate.save("output.mp3")
|
| 10 |
+
|
| 11 |
+
# ✅ Wrapper for Gradio (since Gradio is sync, and edge-tts is async)
|
| 12 |
+
def tts_wrapper(text, voice):
|
| 13 |
+
asyncio.run(generate_speech(text, voice))
|
| 14 |
+
return "output.mp3"
|
| 15 |
+
|
| 16 |
+
# ✅ Voice options
|
| 17 |
+
VOICE_OPTIONS = {
|
| 18 |
+
"Aria (Female, US)": "en-US-AriaNeural",
|
| 19 |
+
"Ryan (Male, UK)": "en-GB-RyanNeural",
|
| 20 |
+
"Willem (Male, ZA)": "af-ZA-WillemNeural",
|
| 21 |
+
"Salma (Female, EG)": "ar-EG-SalmaNeural",
|
| 22 |
+
"Guy (Male, US)": "en-US-GuyNeural"
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
# ✅ Gradio Interface
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
fn=tts_wrapper,
|
| 28 |
+
inputs=[
|
| 29 |
+
gr.Textbox(lines=4, placeholder="Enter text to convert to speech"),
|
| 30 |
+
gr.Dropdown(choices=list(VOICE_OPTIONS.values()), label="Select Voice")
|
| 31 |
+
],
|
| 32 |
+
outputs=gr.Audio(type="filepath", label="Generated Speech"),
|
| 33 |
+
title="🎤 Text-to-Speech App with Microsoft Edge TTS",
|
| 34 |
+
description="Type text and select a voice. The app will speak it using edge-tts."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.26.0
|
| 2 |
+
edge-tts>=6.1.10
|