hexgrad commited on
Commit
0983170
·
verified ·
1 Parent(s): b79287b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -242,7 +242,7 @@ def clamp_speed(speed):
242
  return speed
243
 
244
  # Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
245
- def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto', sk=''):
246
  voices = resolve_voices(voice, warn=ps)
247
  ps = ps or phonemize(text, voice)
248
  speed = clamp_speed(speed)
@@ -256,7 +256,9 @@ def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto', sk='
256
  tokens = tokens[:510]
257
  ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
258
  use_gpu = len(ps) > 99 if use_gpu == 'auto' else use_gpu
259
- assert sk == os.environ['SK']
 
 
260
  try:
261
  if use_gpu:
262
  out = forward_gpu(tokens, voices, speed)
@@ -269,14 +271,14 @@ def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto', sk='
269
  out = forward(tokens, voices, speed)
270
  else:
271
  raise gr.Error(e)
272
- print('🔥', datetime.now(), text, voices, ps, use_gpu, repr(e))
273
  return (None, '')
274
  trim = int(trim / speed)
275
  if trim > 0:
276
  if trim * 2 >= len(out):
277
  return (None, '')
278
  out = out[trim:-trim]
279
- print('🔥', datetime.now(), text, voices, ps, use_gpu)
280
  return ((SAMPLE_RATE, out), ps)
281
 
282
  def toggle_autoplay(autoplay):
@@ -335,7 +337,7 @@ with gr.Blocks() as basic_tts:
335
  voice.change(lambda v, b: gr.Button(b, variant='primary' if v.startswith(b[:2]) else 'secondary'), inputs=[voice, btn], outputs=[btn])
336
  with gr.Row():
337
  sk = gr.Textbox(visible=False)
338
- text.focus(lambda: os.environ['SK'], outputs=[sk])
339
  text.submit(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu, sk], outputs=[audio, out_ps])
340
  generate_btn.click(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu, sk], outputs=[audio, out_ps])
341
 
 
242
  return speed
243
 
244
  # Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
245
+ def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto', sk=None):
246
  voices = resolve_voices(voice, warn=ps)
247
  ps = ps or phonemize(text, voice)
248
  speed = clamp_speed(speed)
 
256
  tokens = tokens[:510]
257
  ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
258
  use_gpu = len(ps) > 99 if use_gpu == 'auto' else use_gpu
259
+ if sk != os.environ['SK']:
260
+ print('❌', datetime.now(), text, voices, ps, use_gpu)
261
+ return (None, '')
262
  try:
263
  if use_gpu:
264
  out = forward_gpu(tokens, voices, speed)
 
271
  out = forward(tokens, voices, speed)
272
  else:
273
  raise gr.Error(e)
274
+ print('🔥', datetime.now(), len(ps), use_gpu, repr(e))
275
  return (None, '')
276
  trim = int(trim / speed)
277
  if trim > 0:
278
  if trim * 2 >= len(out):
279
  return (None, '')
280
  out = out[trim:-trim]
281
+ print('🔥', datetime.now(), len(ps), use_gpu, len(out))
282
  return ((SAMPLE_RATE, out), ps)
283
 
284
  def toggle_autoplay(autoplay):
 
337
  voice.change(lambda v, b: gr.Button(b, variant='primary' if v.startswith(b[:2]) else 'secondary'), inputs=[voice, btn], outputs=[btn])
338
  with gr.Row():
339
  sk = gr.Textbox(visible=False)
340
+ text.change(lambda: os.environ['SK'], outputs=[sk])
341
  text.submit(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu, sk], outputs=[audio, out_ps])
342
  generate_btn.click(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu, sk], outputs=[audio, out_ps])
343