Anjiurine
commited on
Commit
•
0d53fd0
1
Parent(s):
f164127
- README.md +1 -3
- app.py +96 -0
- requirements.txt +2 -0
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 🏆
|
4 |
colorFrom: indigo
|
5 |
colorTo: pink
|
@@ -8,5 +8,3 @@ sdk_version: 4.13.0
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: edge-tts-webui
|
3 |
emoji: 🏆
|
4 |
colorFrom: indigo
|
5 |
colorTo: pink
|
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import edge_tts
|
3 |
+
import asyncio
|
4 |
+
import os
|
5 |
+
|
6 |
+
SUPPORTED_VOICES = {
|
7 |
+
'Xiaoxiao-晓晓': 'zh-CN-XiaoxiaoNeural',
|
8 |
+
'Xiaoyi-晓伊': 'zh-CN-XiaoyiNeural',
|
9 |
+
'Yunjian-云健': 'zh-CN-YunjianNeural',
|
10 |
+
'Yunxi-云希': 'zh-CN-YunxiNeural',
|
11 |
+
'Yunxia-云夏': 'zh-CN-YunxiaNeural',
|
12 |
+
'Yunyang-云扬': 'zh-CN-YunyangNeural',
|
13 |
+
'liaoning-Xiaobei-晓北辽宁': 'zh-CN-liaoning-XiaobeiNeural',
|
14 |
+
'shaanxi-Xiaoni-陕西晓妮': 'zh-CN-shaanxi-XiaoniNeural'
|
15 |
+
}
|
16 |
+
|
17 |
+
async def changeVoice(voices):
|
18 |
+
example = SUPPORTED_VOICES[voices]
|
19 |
+
example_file = os.path.join(os.path.dirname(__file__), "example/"+example+".wav")
|
20 |
+
return example_file
|
21 |
+
|
22 |
+
async def textToSpeech(text, voices, rate, volume):
|
23 |
+
output_file = "output.mp3"
|
24 |
+
voices = SUPPORTED_VOICES[voices]
|
25 |
+
rates = "+" + str(rate) + "%" if rate >= 0 else str(rate) + "%"
|
26 |
+
volumes = "+" + str(volume) + "%" if volume >= 0 else str(volume) + "%"
|
27 |
+
|
28 |
+
communicate = edge_tts.Communicate(text, voices, rate=rates, volume=volumes, proxy=None)
|
29 |
+
await communicate.save(output_file)
|
30 |
+
|
31 |
+
audio_file = os.path.join(os.path.dirname(__file__), "output.mp3")
|
32 |
+
if os.path.exists(audio_file):
|
33 |
+
return audio_file
|
34 |
+
else:
|
35 |
+
raise gr.Error("转换失败!")
|
36 |
+
|
37 |
+
async def clearSpeech():
|
38 |
+
output_file = os.path.join(os.path.dirname(__file__), "output.mp3")
|
39 |
+
if os.path.exists(output_file):
|
40 |
+
os.remove(output_file)
|
41 |
+
return None, None
|
42 |
+
|
43 |
+
async def main():
|
44 |
+
with gr.Blocks(title="Edge TTS") as demo:
|
45 |
+
gr.Markdown("""
|
46 |
+
# Edge TTS
|
47 |
+
""")
|
48 |
+
with gr.Row():
|
49 |
+
with gr.Column():
|
50 |
+
text = gr.TextArea(label="文本", elem_classes="text-area")
|
51 |
+
btn = gr.Button("生成", elem_id="submit-btn")
|
52 |
+
with gr.Column():
|
53 |
+
voices = gr.Dropdown(choices=[
|
54 |
+
"Xiaoxiao-晓晓", "Xiaoyi-晓伊", "Yunjian-云健", "Yunxi-云希",
|
55 |
+
"Yunxia-云夏", "Yunyang-云扬", "liaoning-Xiaobei-晓北辽宁",
|
56 |
+
"shaanxi-Xiaoni-陕西晓妮"
|
57 |
+
],
|
58 |
+
value="Xiaoxiao-晓晓",
|
59 |
+
label="发音",
|
60 |
+
info="请选择发音人",
|
61 |
+
interactive=True)
|
62 |
+
|
63 |
+
example = gr.Audio(label="试听",
|
64 |
+
value="example/zh-CN-XiaoxiaoNeural.wav",
|
65 |
+
interactive=False,
|
66 |
+
elem_classes="example")
|
67 |
+
|
68 |
+
voices.change(fn=changeVoice, inputs=voices, outputs=example)
|
69 |
+
rate = gr.Slider(-100,
|
70 |
+
100,
|
71 |
+
step=1,
|
72 |
+
value=0,
|
73 |
+
label="语速增减",
|
74 |
+
info="加快或减慢语速",
|
75 |
+
interactive=True)
|
76 |
+
|
77 |
+
volume = gr.Slider(-100,
|
78 |
+
100,
|
79 |
+
step=1,
|
80 |
+
value=0,
|
81 |
+
label="音调增减",
|
82 |
+
info="加大或减小音调",
|
83 |
+
interactive=True)
|
84 |
+
audio = gr.Audio(label="输出",
|
85 |
+
interactive=False,
|
86 |
+
elem_classes="audio")
|
87 |
+
clear = gr.Button("清除", elem_id="clear-btn")
|
88 |
+
btn.click(fn=textToSpeech,
|
89 |
+
inputs=[text, voices, rate, volume],
|
90 |
+
outputs=[audio])
|
91 |
+
clear.click(fn=clearSpeech, outputs=[text, audio])
|
92 |
+
|
93 |
+
if __name__ == "__main__":
|
94 |
+
await demo.launch()
|
95 |
+
|
96 |
+
asyncio.run(main())
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
edge-tts
|
2 |
+
gradio
|