mbarnig commited on
Commit
7c99d61
·
verified ·
1 Parent(s): 63564d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -8
app.py CHANGED
@@ -7,13 +7,11 @@ import requests
7
  from pypipertts import PyPiper
8
  pp=PyPiper()
9
 
10
- length=1
11
- noise=1
12
- width=1
13
- sen_pause=1
14
- stream=True
15
 
16
- def load_mod(instr="lb_LU-marylux-medium"):
17
  load_mes=gr.Info(f"""Loading Model...<br>{instr}""",duration=2)
18
  pp.load_mod(instr=instr)
19
  with open(pp.json_ob,'r') as f:
@@ -40,7 +38,15 @@ def load_set(set_file):
40
  gr.update(value=set_json['noise']),gr.update(value=set_json['width']),
41
  gr.update(value=set_json['pause']))
42
  txt="""PiperTTS is a powerful text-to-speech TTS node designed to convert written text into high-quality spoken audio. This node leverages advanced voice synthesis models to generate natural-sounding speech, making it an invaluable tool for AI developers looking to add a vocal element to their projects."""
43
-
 
 
 
 
 
 
 
 
44
  def button_on(stream):
45
  if stream==True:
46
  return gr.update(interactive=True,visible=True),gr.update(interactive=False,visible=False)
@@ -48,7 +54,7 @@ def button_on(stream):
48
  return gr.update(interactive=False,visible=False),gr.update(interactive=True,visible=True)
49
  def clear_aud():
50
  return None
51
- with gr.Blocks() as b:
52
  gr.HTML("""<h1 style='font-size:xxx-large;font-weight:900;'>Piper Fast TTS</h1>
53
  <h4>Piper: <a href='https://github.com/rhasspy/piper' target='_blank'>https://github.com/rhasspy/piper</a></h4>
54
  <h4>PyPiperTTS: <a href='https://github.com/broadfield-dev/PyPiperTTS' target='_blank'>https://github.com/broadfield-dev/PyPiperTTS</a></h4>
@@ -62,5 +68,33 @@ with gr.Blocks() as b:
62
  sub_btn=gr.Button(interactive=False,visible=False)
63
  cancel_btn=gr.Button("Stop")
64
  out_aud=gr.Audio(streaming=True, autoplay=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  b.queue(default_concurrency_limit=20).launch(max_threads=40)
 
7
  from pypipertts import PyPiper
8
  pp=PyPiper()
9
 
10
+ def init():
11
+ key_list=pp.key_list
12
+ return(gr.update(label="Voice",choices=key_list,value="en_US-joe-medium",interactive=True))
 
 
13
 
14
+ def load_mod(instr="en_US-joe-medium"):
15
  load_mes=gr.Info(f"""Loading Model...<br>{instr}""",duration=2)
16
  pp.load_mod(instr=instr)
17
  with open(pp.json_ob,'r') as f:
 
38
  gr.update(value=set_json['noise']),gr.update(value=set_json['width']),
39
  gr.update(value=set_json['pause']))
40
  txt="""PiperTTS is a powerful text-to-speech TTS node designed to convert written text into high-quality spoken audio. This node leverages advanced voice synthesis models to generate natural-sounding speech, making it an invaluable tool for AI developers looking to add a vocal element to their projects."""
41
+ def exp1():
42
+ exp_file=f"./example/en_US-libritts-high__1_4__0_3__0_2__1.json"
43
+ return(gr.update(value=txt),gr.update(value=exp_file))
44
+ def exp2():
45
+ exp_file=f"./example/en_US-ryan-high__1__0_6__0_01__1.json"
46
+ return(gr.update(value=txt),gr.update(value=exp_file))
47
+ def exp3():
48
+ exp_file=f"./example/en_US-ljspeech-high__1__1__0_5__1.json"
49
+ return(gr.update(value=txt),gr.update(value=exp_file))
50
  def button_on(stream):
51
  if stream==True:
52
  return gr.update(interactive=True,visible=True),gr.update(interactive=False,visible=False)
 
54
  return gr.update(interactive=False,visible=False),gr.update(interactive=True,visible=True)
55
  def clear_aud():
56
  return None
57
+ with gr.Blocks(theme="Hev832/Applio-Theme") as b:
58
  gr.HTML("""<h1 style='font-size:xxx-large;font-weight:900;'>Piper Fast TTS</h1>
59
  <h4>Piper: <a href='https://github.com/rhasspy/piper' target='_blank'>https://github.com/rhasspy/piper</a></h4>
60
  <h4>PyPiperTTS: <a href='https://github.com/broadfield-dev/PyPiperTTS' target='_blank'>https://github.com/broadfield-dev/PyPiperTTS</a></h4>
 
68
  sub_btn=gr.Button(interactive=False,visible=False)
69
  cancel_btn=gr.Button("Stop")
70
  out_aud=gr.Audio(streaming=True, autoplay=True)
71
+ with gr.Column(scale=1):
72
+ with gr.Accordion("Control"):
73
+ stream=gr.Checkbox(label="Stream",info="Streaming is fast, but lower quality",value=True,interactive=True)
74
+ length=gr.Slider(label="Length", minimum=0.01, maximum=10.0, value=1)
75
+ noise=gr.Slider(label="Noise", minimum=0.01, maximum=3.0, value=1)
76
+ width=gr.Slider(label="Noise Width", minimum=0.01, maximum=3.0, value=1)
77
+ sen_pause=gr.Slider(label="Sentence Pause", minimum=0.1, maximum=10.0, value=1)
78
+ with gr.Tab("Save Settings"):
79
+ save_btn=gr.Button("Save")
80
+ save_file=gr.File()
81
+ with gr.Tab("Load Settings"):
82
+ load_file=gr.File()
83
+ with gr.Column(scale=1):
84
+ expbtn1=gr.Button("Example 1").click(exp1,None,[in_txt,load_file])
85
+ expbtn2=gr.Button("Example 2").click(exp2,None,[in_txt,load_file])
86
+ expbtn3=gr.Button("Example 3").click(exp3,None,[in_txt,load_file])
87
+ with gr.Accordion("Model Config"):
88
+ json_ob=gr.JSON(label="JSON")
89
+ f1=stream.change(button_on,stream,[stream_btn,sub_btn])
90
+ f2=save_btn.click(save_set,[names,length,noise,width,sen_pause],save_file)
91
+ f3=load_file.change(load_set,load_file,[names,length,noise,width,sen_pause])
92
+ f4=names.change(load_mod,names,json_ob).then(clear_aud,None,out_aud)
93
+ f5=stream_btn.click(clear_aud,None,out_aud)
94
+ f6=stream_btn.click(pp.stream_tts,[in_txt,names,length,noise,width,sen_pause],out_aud)
95
+ f7=sub_btn.click(clear_aud,None,out_aud)
96
+ f8=sub_btn.click(pp.tts,[in_txt,names,length,noise,width,sen_pause],out_aud)
97
+ cancel_btn.click(None,None,None,cancels=[f1,f2,f3,f4,f5,f6,f7,f8])
98
+ b.load(init,None,names)
99
 
100
  b.queue(default_concurrency_limit=20).launch(max_threads=40)