changxin commited on
Commit
1e14657
1 Parent(s): 5d0f064

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -3
app.py CHANGED
@@ -1,13 +1,41 @@
1
  import gradio as gr
2
  import hashlib
 
 
 
3
  def fx(x:str):
4
  hash=hashlib.md5()
5
  hash.update(x.encode(encoding='utf-8'))
6
  return hash.hexdigest()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo=gr.Blocks()
8
  with demo:
9
- text_input=gr.Textbox(placeholder='请输入测试字符串',label="请输入需要MD5加密的测试内容")
10
- bb_button=gr.Button("运行")
11
- bb_button.click(fx, inputs=text_input, outputs=gr.Textbox(label="输出"),api_name='md5')
 
 
 
 
 
12
  demo.launch()
13
 
 
1
  import gradio as gr
2
  import hashlib
3
+ import tempfile
4
+ from TTS.utils.manage import ModelManager
5
+ from TTS.utils.synthesizer import Synthesizer
6
  def fx(x:str):
7
  hash=hashlib.md5()
8
  hash.update(x.encode(encoding='utf-8'))
9
  return hash.hexdigest()
10
+
11
+ examples = [
12
+ ["语音合成是通过机械的、电子的方法产生人造语音的技术。"],
13
+ ["李显龙总理表示,我国要达到像意大利的开放程度,几乎回到冠病疫情前的生活,还需要一段时间。"]
14
+ ]
15
+
16
+
17
+ manager = ModelManager()
18
+ model_path, config_path, model_item = manager.download_model("tts_models/zh-CN/baker/tacotron2-DDC-GST")
19
+ synthesizer = Synthesizer(
20
+ model_path, config_path, None, None, None,
21
+ )
22
+
23
+
24
+ def inference(text: str):
25
+ wavs = synthesizer.tts(text)
26
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
27
+ synthesizer.save_wav(wavs, fp)
28
+ return fp.name
29
+
30
  demo=gr.Blocks()
31
  with demo:
32
+ with gr.Row():
33
+ text_input=gr.Textbox(placeholder='请输入测试字符串',label="请输入需要MD5加密的测试内容")
34
+ bb_button=gr.Button("运行")
35
+ bb_button.click(fx, inputs=text_input, outputs=gr.Textbox(label="输出"),api_name='md5')
36
+ with gr.Row():
37
+ TTS_input=gr.Textbox(label="输入文本",default="你好吗?我很好。")
38
+ TTS_button=gr.Button("合成")
39
+ bb_button.click(inference, inputs=TTS_input, outputs=gr.Audio(label="输出合成结果"),examples=examples)
40
  demo.launch()
41