hexgrad commited on
Commit
d959cb1
·
verified ·
1 Parent(s): 2acb6ca

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -184,10 +184,10 @@ def generate(text, voice, ps=None, speed=1.0, reduce_noise=0.5, opening_cut=4000
184
  ease_out = min(int(ease_out / speed), len(out)//2)
185
  for i in range(ease_out):
186
  out[-i-1] *= s_curve(i / ease_out)
187
- pad_before = max(0, int(pad_before / speed))
188
  if pad_before > 0:
189
  out = np.concatenate([np.zeros(pad_before), out])
190
- pad_after = max(0, int(pad_after / speed))
191
  if pad_after > 0:
192
  out = np.concatenate([out, np.zeros(pad_after)])
193
  return ((SAMPLE_RATE, out), ps)
@@ -314,13 +314,12 @@ def segment_and_tokenize(text, voice, skip_square_brackets=True, newline_split=2
314
  segments = [row for t in texts for row in recursive_split(t, voice)]
315
  return [(i, *row) for i, row in enumerate(segments)]
316
 
317
- def lf_generate(segments, voice, speed=1.0, reduce_noise=0.5, opening_cut=4000, closing_cut=2000, ease_in=3000, ease_out=1000, pad_before=5000, pad_after=5000):
318
  token_lists = list(map(tokenize, segments['Tokens']))
319
  wavs = []
320
- opening_cut = max(0, int(opening_cut / speed))
321
- closing_cut = max(0, int(closing_cut / speed))
322
- pad_before = max(0, int(pad_before / speed))
323
- pad_after = max(0, int(pad_after / speed))
324
  batch_size = 100
325
  for i in range(0, len(token_lists), batch_size):
326
  try:
@@ -344,11 +343,15 @@ def lf_generate(segments, voice, speed=1.0, reduce_noise=0.5, opening_cut=4000,
344
  ease_out = min(int(ease_out / speed), len(out)//2)
345
  for i in range(ease_out):
346
  out[-i-1] *= s_curve(i / ease_out)
347
- if pad_before > 0:
348
- wavs.append(np.zeros(pad_before))
349
  wavs.append(out)
350
- if pad_after > 0:
351
- wavs.append(np.zeros(pad_after))
 
 
 
 
352
  return (SAMPLE_RATE, np.concatenate(wavs)) if wavs else None
353
 
354
  def did_change_segments(segments):
@@ -400,14 +403,16 @@ with gr.Blocks() as lf_tts:
400
  ease_out = gr.Slider(minimum=0, maximum=24000, value=1000, step=1000, label='Ease Out', info='📐 Ease out for this many samples, before closing cut.')
401
  with gr.Row():
402
  with gr.Column():
403
- pad_before = gr.Slider(minimum=0, maximum=24000, value=5000, step=1000, label='Pad Before', info='🔇 How many samples of silence to insert before each segment.')
404
  with gr.Column():
405
- pad_after = gr.Slider(minimum=0, maximum=24000, value=5000, step=1000, label='Pad After', info='🔇 How many samples of silence to append after each segment.')
 
 
406
  with gr.Row():
407
  segments = gr.Dataframe(headers=['#', 'Text', 'Tokens', 'Length'], row_count=(1, 'dynamic'), col_count=(4, 'fixed'), label='Segments', interactive=False, wrap=True)
408
  segments.change(fn=did_change_segments, inputs=[segments], outputs=[segment_btn, generate_btn])
409
  segment_btn.click(segment_and_tokenize, inputs=[text, voice, skip_square_brackets, newline_split], outputs=[segments])
410
- generate_btn.click(lf_generate, inputs=[segments, voice, speed, reduce_noise, opening_cut, closing_cut, ease_in, ease_out, pad_before, pad_after], outputs=[audio])
411
 
412
  with gr.Blocks() as app:
413
  gr.TabbedInterface(
 
184
  ease_out = min(int(ease_out / speed), len(out)//2)
185
  for i in range(ease_out):
186
  out[-i-1] *= s_curve(i / ease_out)
187
+ pad_before = int(pad_before / speed)
188
  if pad_before > 0:
189
  out = np.concatenate([np.zeros(pad_before), out])
190
+ pad_after = int(pad_after / speed)
191
  if pad_after > 0:
192
  out = np.concatenate([out, np.zeros(pad_after)])
193
  return ((SAMPLE_RATE, out), ps)
 
314
  segments = [row for t in texts for row in recursive_split(t, voice)]
315
  return [(i, *row) for i, row in enumerate(segments)]
316
 
317
+ def lf_generate(segments, voice, speed=1.0, reduce_noise=0.5, opening_cut=4000, closing_cut=2000, ease_in=3000, ease_out=1000, pad_before=5000, pad_after=5000, pad_between=10000):
318
  token_lists = list(map(tokenize, segments['Tokens']))
319
  wavs = []
320
+ opening_cut = int(opening_cut / speed)
321
+ closing_cut = int(closing_cut / speed)
322
+ pad_between = int(pad_between / speed)
 
323
  batch_size = 100
324
  for i in range(0, len(token_lists), batch_size):
325
  try:
 
343
  ease_out = min(int(ease_out / speed), len(out)//2)
344
  for i in range(ease_out):
345
  out[-i-1] *= s_curve(i / ease_out)
346
+ if wavs and pad_between > 0:
347
+ wavs.append(np.zeros(pad_between))
348
  wavs.append(out)
349
+ pad_before = int(pad_before / speed)
350
+ if pad_before > 0:
351
+ wavs.insert(0, np.zeros(pad_before))
352
+ pad_after = int(pad_after / speed)
353
+ if pad_after > 0:
354
+ wavs.append(np.zeros(pad_after))
355
  return (SAMPLE_RATE, np.concatenate(wavs)) if wavs else None
356
 
357
  def did_change_segments(segments):
 
403
  ease_out = gr.Slider(minimum=0, maximum=24000, value=1000, step=1000, label='Ease Out', info='📐 Ease out for this many samples, before closing cut.')
404
  with gr.Row():
405
  with gr.Column():
406
+ pad_before = gr.Slider(minimum=0, maximum=24000, value=5000, step=1000, label='Pad Before', info='🔇 How many samples of silence to insert before the start.')
407
  with gr.Column():
408
+ pad_after = gr.Slider(minimum=0, maximum=24000, value=5000, step=1000, label='Pad After', info='🔇 How many samples of silence to append after the end.')
409
+ with gr.Row():
410
+ pad_between = gr.Slider(minimum=0, maximum=24000, value=10000, step=1000, label='Pad Between', info='🔇 How many samples of silence to insert between segments.')
411
  with gr.Row():
412
  segments = gr.Dataframe(headers=['#', 'Text', 'Tokens', 'Length'], row_count=(1, 'dynamic'), col_count=(4, 'fixed'), label='Segments', interactive=False, wrap=True)
413
  segments.change(fn=did_change_segments, inputs=[segments], outputs=[segment_btn, generate_btn])
414
  segment_btn.click(segment_and_tokenize, inputs=[text, voice, skip_square_brackets, newline_split], outputs=[segments])
415
+ generate_btn.click(lf_generate, inputs=[segments, voice, speed, reduce_noise, opening_cut, closing_cut, ease_in, ease_out, pad_before, pad_after, pad_between], outputs=[audio])
416
 
417
  with gr.Blocks() as app:
418
  gr.TabbedInterface(