File size: 2,282 Bytes
3b87861 c451602 1e14657 4cad25d 1e14657 3b87861 c451602 1e14657 4cad25d 1e14657 dfa4c0a 12e6a54 4cad25d d9217c2 3b87861 |
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import gradio as gr
import hashlib
import tempfile
import requests
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()
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
headers= {"Content-Type": "application/json"}
url="https://m-formatter.azurewebsites.net/api/v2"
def fx_m(s:str):
data={'code':s,'resultType':'text'}
respose=requests.post(url, json=data, headers)
return respose.text
demo=gr.Blocks()
with demo:
with gr.Tabs():
with gr.TabItem("测试1"):
with gr.Column():
text_input=gr.Textbox(placeholder='请输入测试字符串',label="请输入需要MD5加密的测试内容")
text_output=gr.Textbox(label="输出",visible=False)
text_input.change(fn=lambda visible: gr.update(visible=True), inputs=text_input, outputs=text_output)
bb_button=gr.Button("运行")
bb_button.click(fx, inputs=text_input, outputs=text_output,api_name='md5')
with gr.Column():
gr.Markdown("# TTS文本字符串转语音合成训练")
TTS_input=gr.Textbox(label="输入文本",default="你好吗?我很好。")
TTS_button=gr.Button("合成")
TTS_button.click(inference, inputs=TTS_input, outputs=gr.Audio(label="输出合成结果"),api_name='tts')
with gr.TabItem("M-Formatter"):
gr.Markdown("# PowerQuery M语言脚本格式化测试")
M_input=gr.Textbox(label="请填写需要格式化的M脚本",default="let a=1,b=2 in a+b",lines=28)
M_output=gr.Textbox(label="格式化结果",lines=50)
M_button=gr.Button("开始格式化>>")
M_button.click(fx_m, inputs=M_input, outputs=M_output,api_name='M')
demo.launch()
|