Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,34 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
| 1 |
+
import edge_tts
|
| 2 |
import gradio as gr
|
| 3 |
+
import tempfile
|
| 4 |
+
import anyio
|
| 5 |
|
| 6 |
+
# Define the available languages and their corresponding voices
|
| 7 |
+
language_dict = {
|
| 8 |
+
"en": "en-US-JennyNeural",
|
| 9 |
+
"en2": "en-US-GuyNeural",
|
| 10 |
+
# Add more languages and voices as needed
|
| 11 |
+
}
|
| 12 |
|
| 13 |
+
async def text_to_speech_edge(text, language_code):
|
| 14 |
+
voice = language_dict.get(language_code, "default_voice")
|
| 15 |
+
communicate = edge_tts.Communicate(text, voice)
|
| 16 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
| 17 |
+
tmp_path = tmp_file.name
|
| 18 |
+
await communicate.save(tmp_path)
|
| 19 |
+
return f"Speech synthesis completed for: {text}", tmp_path
|
| 20 |
|
| 21 |
+
input_text = gr.inputs.Textbox(lines=5, label="Input Text")
|
| 22 |
+
output_text = gr.outputs.Textbox(label="Output Text")
|
| 23 |
+
output_audio = gr.outputs.Audio(type="filepath", label="Exported Audio")
|
| 24 |
+
language = gr.inputs.Dropdown(choices=list(language_dict.keys()), label="Language")
|
| 25 |
|
| 26 |
+
interface = gr.Interface(
|
| 27 |
+
fn=text_to_speech_edge,
|
| 28 |
+
inputs=[input_text, language],
|
| 29 |
+
outputs=[output_text, output_audio],
|
| 30 |
+
title="Edge TTS Text-to-Speech"
|
| 31 |
+
)
|
| 32 |
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
anyio.run(interface.launch, backend="asyncio")
|