Update app.py
Browse files
app.py
CHANGED
|
@@ -4,17 +4,15 @@ import asyncio
|
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
# Get all available voices
|
| 8 |
async def get_voices():
|
| 9 |
voices = await edge_tts.list_voices()
|
| 10 |
return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
|
| 11 |
|
| 12 |
-
# Text-to-speech function
|
| 13 |
async def text_to_speech(text, voice, rate, pitch):
|
| 14 |
if not text.strip():
|
| 15 |
-
return None,
|
| 16 |
if not voice:
|
| 17 |
-
return None,
|
| 18 |
|
| 19 |
voice_short_name = voice.split(" - ")[0]
|
| 20 |
rate_str = f"{rate:+d}%"
|
|
@@ -25,13 +23,11 @@ async def text_to_speech(text, voice, rate, pitch):
|
|
| 25 |
await communicate.save(tmp_path)
|
| 26 |
return tmp_path, None
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
# Create Gradio application
|
| 34 |
-
import gradio as gr
|
| 35 |
|
| 36 |
async def create_demo():
|
| 37 |
voices = await get_voices()
|
|
@@ -74,7 +70,10 @@ async def create_demo():
|
|
| 74 |
)
|
| 75 |
return demo
|
| 76 |
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
if __name__ == "__main__":
|
| 79 |
-
|
| 80 |
-
demo.launch(show_api=False)
|
|
|
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
|
|
|
|
| 7 |
async def get_voices():
|
| 8 |
voices = await edge_tts.list_voices()
|
| 9 |
return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
|
| 10 |
|
|
|
|
| 11 |
async def text_to_speech(text, voice, rate, pitch):
|
| 12 |
if not text.strip():
|
| 13 |
+
return None, "Please enter text to convert."
|
| 14 |
if not voice:
|
| 15 |
+
return None, "Please select a voice."
|
| 16 |
|
| 17 |
voice_short_name = voice.split(" - ")[0]
|
| 18 |
rate_str = f"{rate:+d}%"
|
|
|
|
| 23 |
await communicate.save(tmp_path)
|
| 24 |
return tmp_path, None
|
| 25 |
|
| 26 |
+
async def tts_interface(text, voice, rate, pitch):
|
| 27 |
+
audio, warning = await text_to_speech(text, voice, rate, pitch)
|
| 28 |
+
if warning:
|
| 29 |
+
return audio, gr.Warning(warning)
|
| 30 |
+
return audio, None
|
|
|
|
|
|
|
| 31 |
|
| 32 |
async def create_demo():
|
| 33 |
voices = await get_voices()
|
|
|
|
| 70 |
)
|
| 71 |
return demo
|
| 72 |
|
| 73 |
+
async def main():
|
| 74 |
+
demo = await create_demo()
|
| 75 |
+
demo.queue(default_concurrency_limit=5)
|
| 76 |
+
demo.launch(show_api=False)
|
| 77 |
+
|
| 78 |
if __name__ == "__main__":
|
| 79 |
+
asyncio.run(main())
|
|
|