import gradio as gr import hashlib import tempfile from TTS.utils.manage import ModelManager from TTS.utils.synthesizer import Synthesizer def fx(x:str): hash=hashlib.md5() hash.update(x.encode(encoding='utf-8')) return hash.hexdigest() examples = [ ["语音合成是通过机械的、电子的方法产生人造语音的技术。"], ["李显龙总理表示,我国要达到像意大利的开放程度,几乎回到冠病疫情前的生活,还需要一段时间。"] ] manager = ModelManager() model_path, config_path, model_item = manager.download_model("tts_models/zh-CN/baker/tacotron2-DDC-GST") synthesizer = Synthesizer( model_path, config_path, None, None, None, ) def inference(text: str): wavs = synthesizer.tts(text) with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp: synthesizer.save_wav(wavs, fp) return fp.name demo=gr.Blocks() with demo: with gr.Row(): text_input=gr.Textbox(placeholder='请输入测试字符串',label="请输入需要MD5加密的测试内容") bb_button=gr.Button("运行") bb_button.click(fx, inputs=text_input, outputs=gr.Textbox(label="输出"),api_name='md5') with gr.Row(): TTS_input=gr.Textbox(label="输入文本",default="你好吗?我很好。") TTS_button=gr.Button("合成") bb_button.click(inference, inputs=TTS_input, outputs=gr.Audio(label="输出合成结果"),examples=examples) demo.launch()