hexgrad commited on
Commit
784c478
·
verified ·
1 Parent(s): d01e985

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -279,6 +279,14 @@ def clamp_trim(trim):
279
  return 0.5
280
  return trim
281
 
 
 
 
 
 
 
 
 
282
  # Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
283
  def generate(text, voice='af', ps=None, speed=1, trim=0.5, use_gpu='auto', sk=None):
284
  ps = ps or phonemize(text, voice)
@@ -312,11 +320,7 @@ def generate(text, voice='af', ps=None, speed=1, trim=0.5, use_gpu='auto', sk=No
312
  raise gr.Error(e)
313
  print(debug, datetime.now(), voices, len(ps), use_gpu, repr(e))
314
  return (None, '')
315
- if trim:
316
- a, b = librosa.effects.trim(out, top_db=30)[1]
317
- a = int(a*trim)
318
- b = int(len(out)-(len(out)-b)*trim)
319
- out = out[a:b]
320
  print(debug, datetime.now(), voices, len(ps), use_gpu, len(out))
321
  return ((SAMPLE_RATE, out), ps)
322
 
@@ -499,13 +503,9 @@ def lf_generate(segments, voice, speed=1, trim=0, pad_between=0, use_gpu=True, s
499
  else:
500
  raise gr.Error(e)
501
  for out in outs:
502
- if trim:
503
- a, b = librosa.effects.trim(out, top_db=30)[1]
504
- a = int(a*trim)
505
- b = int(len(out)-(len(out)-b)*trim)
506
- out = out[a:b]
507
  if i > 0 and pad_between > 0:
508
  yield (SAMPLE_RATE, np.zeros(pad_between))
 
509
  yield (SAMPLE_RATE, out)
510
  i += bs
511
 
@@ -618,6 +618,7 @@ This Space and the underlying Kokoro model are both under development and subjec
618
  with gr.Blocks() as changelog:
619
  gr.Markdown('''
620
  **30 Nov 2024**<br/>
 
621
  🏆 https://hf.co/spaces/Pendrokar/TTS-Spaces-Arena
622
 
623
  **28 Nov 2024**<br/>
 
279
  return 0.5
280
  return trim
281
 
282
+ def trim_if_needed(out, trim):
283
+ if not trim:
284
+ return out
285
+ a, b = librosa.effects.trim(out, top_db=30)[1]
286
+ a = int(a*trim)
287
+ b = int(len(out)-(len(out)-b)*trim)
288
+ return out[a:b]
289
+
290
  # Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
291
  def generate(text, voice='af', ps=None, speed=1, trim=0.5, use_gpu='auto', sk=None):
292
  ps = ps or phonemize(text, voice)
 
320
  raise gr.Error(e)
321
  print(debug, datetime.now(), voices, len(ps), use_gpu, repr(e))
322
  return (None, '')
323
+ out = trim_if_needed(out, trim)
 
 
 
 
324
  print(debug, datetime.now(), voices, len(ps), use_gpu, len(out))
325
  return ((SAMPLE_RATE, out), ps)
326
 
 
503
  else:
504
  raise gr.Error(e)
505
  for out in outs:
 
 
 
 
 
506
  if i > 0 and pad_between > 0:
507
  yield (SAMPLE_RATE, np.zeros(pad_between))
508
+ out = trim_if_needed(out, trim)
509
  yield (SAMPLE_RATE, out)
510
  i += bs
511
 
 
618
  with gr.Blocks() as changelog:
619
  gr.Markdown('''
620
  **30 Nov 2024**<br/>
621
+ ✂️ Better trimming with `librosa.effects.trim`
622
  🏆 https://hf.co/spaces/Pendrokar/TTS-Spaces-Arena
623
 
624
  **28 Nov 2024**<br/>