Staticaliza commited on
Commit
cb1604b
·
verified ·
1 Parent(s): fe87b84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -68,8 +68,9 @@ footer {
68
  def trim_silence(audio, threshold=0.001):
69
  abs_audio = np.abs(audio)
70
  indices = np.where(abs_audio > threshold)[0]
71
- if len(indices) == 0:
72
- return audio
 
73
  start = indices[0]
74
  end = indices[-1] + 1
75
  return audio[start:end]
@@ -78,11 +79,11 @@ def generate(text=DEFAULT_INPUT, voice=DEFAULT_VOICE, speed=1):
78
  text = text.strip()[:CHAR_LIMIT] + "."
79
  pipeline = PIPELINES[voice[0]]
80
  pack = pipeline.load_voice(voice)
 
81
  for _, ps, _ in pipeline(text, voice, speed):
82
  ref_s = pack[len(ps) - 1]
83
  audio = MODEL(ps, ref_s, speed)
84
  return (24000, trim_silence(audio.numpy()))
85
- return None
86
 
87
  def cloud():
88
  print("[CLOUD] | Space maintained.")
@@ -99,8 +100,10 @@ with gr.Blocks(css=css) as main:
99
  speed_input = gr.Slider(minimum=0.5, maximum=2, value=1, step=0.1, label="Speed")
100
  submit = gr.Button("▶")
101
  maintain = gr.Button("☁️")
 
102
  with gr.Column():
103
  output = gr.Audio(label="Output")
 
104
  submit.click(fn=generate, inputs=[input, voice_input, speed_input], outputs=output)
105
  maintain.click(cloud, inputs=[], outputs=[], queue=False)
106
 
 
68
  def trim_silence(audio, threshold=0.001):
69
  abs_audio = np.abs(audio)
70
  indices = np.where(abs_audio > threshold)[0]
71
+
72
+ if len(indices) == 0: return audio
73
+
74
  start = indices[0]
75
  end = indices[-1] + 1
76
  return audio[start:end]
 
79
  text = text.strip()[:CHAR_LIMIT] + "."
80
  pipeline = PIPELINES[voice[0]]
81
  pack = pipeline.load_voice(voice)
82
+
83
  for _, ps, _ in pipeline(text, voice, speed):
84
  ref_s = pack[len(ps) - 1]
85
  audio = MODEL(ps, ref_s, speed)
86
  return (24000, trim_silence(audio.numpy()))
 
87
 
88
  def cloud():
89
  print("[CLOUD] | Space maintained.")
 
100
  speed_input = gr.Slider(minimum=0.5, maximum=2, value=1, step=0.1, label="Speed")
101
  submit = gr.Button("▶")
102
  maintain = gr.Button("☁️")
103
+
104
  with gr.Column():
105
  output = gr.Audio(label="Output")
106
+
107
  submit.click(fn=generate, inputs=[input, voice_input, speed_input], outputs=output)
108
  maintain.click(cloud, inputs=[], outputs=[], queue=False)
109