Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
@@ -242,12 +242,13 @@ 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'):
|
246 |
voices = resolve_voices(voice, warn=ps)
|
247 |
ps = ps or phonemize(text, voice)
|
248 |
speed = clamp_speed(speed)
|
249 |
trim = trim if isinstance(trim, int) else 3000
|
250 |
use_gpu = use_gpu if use_gpu in ('auto', False, True) else 'auto'
|
|
|
251 |
tokens = tokenize(ps)
|
252 |
if not tokens:
|
253 |
return (None, '')
|
@@ -255,14 +256,14 @@ def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto'):
|
|
255 |
tokens = tokens[:510]
|
256 |
ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
|
257 |
use_gpu = len(ps) > 99 if use_gpu == 'auto' else use_gpu
|
258 |
-
|
259 |
try:
|
260 |
if use_gpu:
|
261 |
out = forward_gpu(tokens, voices, speed)
|
262 |
else:
|
263 |
out = forward(tokens, voices, speed)
|
264 |
except gr.exceptions.Error as e:
|
265 |
-
if
|
266 |
gr.Warning(str(e))
|
267 |
gr.Info('Switching to CPU')
|
268 |
out = forward(tokens, voices, speed)
|
@@ -332,8 +333,11 @@ with gr.Blocks() as basic_tts:
|
|
332 |
btn = gr.Button(list(CHOICES.values())[i*4+j], variant='primary' if i*4+j < 10 else 'secondary')
|
333 |
btn.click(lambda v, b: f'{v}+{b}' if v.startswith(b[:2]) else b, inputs=[voice, btn], outputs=[voice])
|
334 |
voice.change(lambda v, b: gr.Button(b, variant='primary' if v.startswith(b[:2]) else 'secondary'), inputs=[voice, btn], outputs=[btn])
|
335 |
-
|
336 |
-
|
|
|
|
|
|
|
337 |
|
338 |
@torch.no_grad()
|
339 |
def lf_forward(token_lists, voices, speed, device='cpu'):
|
@@ -439,7 +443,7 @@ def lf_generate(segments, voice, speed=1, trim=0, pad_between=0, use_gpu=True):
|
|
439 |
else:
|
440 |
outs = lf_forward(tokens, voices, speed)
|
441 |
except gr.exceptions.Error as e:
|
442 |
-
if
|
443 |
gr.Warning(str(e))
|
444 |
gr.Info('Switching to CPU')
|
445 |
outs = lf_forward(tokens, voices, speed)
|
@@ -563,8 +567,7 @@ Random Japanese texts: CC0 public domain from [Common Voice](https://github.com/
|
|
563 |
with gr.Blocks() as changelog:
|
564 |
gr.Markdown('''
|
565 |
**28 Nov 2024**<br/>
|
566 |
-
🌊 Long Form streaming and stop button
|
567 |
-
📡 Telemetry enabled
|
568 |
|
569 |
**25 Nov 2024**<br/>
|
570 |
🎨 Voice Mixer added
|
|
|
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)
|
249 |
trim = trim if isinstance(trim, int) else 3000
|
250 |
use_gpu = use_gpu if use_gpu in ('auto', False, True) else 'auto'
|
251 |
+
sk = os.environ['SK'] if text in sents else sk
|
252 |
tokens = tokenize(ps)
|
253 |
if not tokens:
|
254 |
return (None, '')
|
|
|
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)
|
263 |
else:
|
264 |
out = forward(tokens, voices, speed)
|
265 |
except gr.exceptions.Error as e:
|
266 |
+
if use_gpu:
|
267 |
gr.Warning(str(e))
|
268 |
gr.Info('Switching to CPU')
|
269 |
out = forward(tokens, voices, speed)
|
|
|
333 |
btn = gr.Button(list(CHOICES.values())[i*4+j], variant='primary' if i*4+j < 10 else 'secondary')
|
334 |
btn.click(lambda v, b: f'{v}+{b}' if v.startswith(b[:2]) else b, inputs=[voice, btn], outputs=[voice])
|
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 |
|
342 |
@torch.no_grad()
|
343 |
def lf_forward(token_lists, voices, speed, device='cpu'):
|
|
|
443 |
else:
|
444 |
outs = lf_forward(tokens, voices, speed)
|
445 |
except gr.exceptions.Error as e:
|
446 |
+
if use_gpu:
|
447 |
gr.Warning(str(e))
|
448 |
gr.Info('Switching to CPU')
|
449 |
outs = lf_forward(tokens, voices, speed)
|
|
|
567 |
with gr.Blocks() as changelog:
|
568 |
gr.Markdown('''
|
569 |
**28 Nov 2024**<br/>
|
570 |
+
🌊 Long Form streaming and stop button
|
|
|
571 |
|
572 |
**25 Nov 2024**<br/>
|
573 |
🎨 Voice Mixer added
|