File size: 1,051 Bytes
90010fe
9427c79
90010fe
 
 
 
 
9427c79
1d8831d
d24ab7c
1d8831d
90010fe
1d8831d
90010fe
 
 
 
e893d2f
90010fe
 
 
 
 
e640b1d
 
 
2ca342a
d24ab7c
90010fe
1d8831d
90010fe
 
 
2ca342a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

#from tts_voice import tts_order_voice
import edge_tts
import gradio as gr
import tempfile
import anyio

language_dict = {'普通话 (中国大陆)-Yunxi-男': 'zh-CN-YunxiNeural','普通话 (中国大陆)-Xiaoyi-女': 'zh-CN-XiaoyiNeural'}

def text_to_speech_edge(text, language_code):
    
    voice = language_dict[language_code]
    print(voice)
    communicate = edge_tts.Communicate(text, voice)
    with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
        tmp_path = tmp_file.name

    communicate.save(tmp_path)

    return "语音合成完成:{}".format(text), tmp_path



input_text = gr.Textbox(lines=5, label="输入文本")
output_text = gr.Textbox(label="输出文本")
output_audio = gr.Audio(type="filepath", label="导出文件")

language = gr.Dropdown(choices=list(language_dict.keys()),  label="语言")

interface = gr.Interface(fn=text_to_speech_edge, inputs=[input_text, language], outputs=[output_text, output_audio], title="LZZ文字转语音")


if __name__ == "__main__":
    interface.launch()