Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from tts_voice import tts_order_voice
|
2 |
+
import edge_tts
|
3 |
+
import gradio as gr
|
4 |
+
import tempfile
|
5 |
+
import anyio
|
6 |
+
|
7 |
+
language_dict = tts_order_voice
|
8 |
+
|
9 |
+
async def text_to_speech_edge(text, language_code):
|
10 |
+
voice = language_dict[language_code]
|
11 |
+
communicate = edge_tts.Communicate(text, voice)
|
12 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
13 |
+
tmp_path = tmp_file.name
|
14 |
+
|
15 |
+
await communicate.save(tmp_path)
|
16 |
+
|
17 |
+
return "语音合成完成:{}".format(text), tmp_path
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
input_text = gr.inputs.Textbox(lines=5, label="输入文本")
|
22 |
+
output_text = gr.outputs.Textbox(label="输出文本")
|
23 |
+
output_audio = gr.outputs.Audio(type="filepath", label="导出文件")
|
24 |
+
default_language = list(language_dict.keys())[0]
|
25 |
+
language = gr.inputs.Dropdown(choices=list(language_dict.keys()), default=default_language, label="语言")
|
26 |
+
|
27 |
+
|
28 |
+
interface = gr.Interface(fn=text_to_speech_edge, inputs=[input_text, language], outputs=[output_text, output_audio], title="Edge TTS 文字转语音")
|
29 |
+
|
30 |
+
|
31 |
+
if __name__ == "__main__":
|
32 |
+
anyio.run(interface.launch, backend="asyncio")
|