Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
@@ -244,12 +244,14 @@ def clamp_speed(speed):
|
|
244 |
|
245 |
# Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
|
246 |
def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto', sk=None):
|
|
|
|
|
|
|
247 |
voices = resolve_voices(voice, warn=ps)
|
248 |
ps = ps or phonemize(text, voice)
|
249 |
speed = clamp_speed(speed)
|
250 |
trim = trim if isinstance(trim, int) else 3000
|
251 |
use_gpu = use_gpu if use_gpu in ('auto', False, True) else 'auto'
|
252 |
-
sk = os.environ['SK'] if text in sents else sk
|
253 |
tokens = tokenize(ps)
|
254 |
if not tokens:
|
255 |
return (None, '')
|
@@ -257,9 +259,6 @@ def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto', sk=N
|
|
257 |
tokens = tokens[:510]
|
258 |
ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
|
259 |
use_gpu = len(ps) > 99 if use_gpu == 'auto' else use_gpu
|
260 |
-
if sk != os.environ['SK']:
|
261 |
-
print('❌', datetime.now(), text, voices, ps, sk)
|
262 |
-
return (None, '')
|
263 |
try:
|
264 |
if use_gpu:
|
265 |
out = forward_gpu(tokens, voices, speed, sk)
|
@@ -429,6 +428,8 @@ def segment_and_tokenize(text, voice, skip_square_brackets=True, newline_split=2
|
|
429 |
return [(i, *row) for i, row in enumerate(segments)]
|
430 |
|
431 |
def lf_generate(segments, voice, speed=1, trim=0, pad_between=0, use_gpu=True, sk=None):
|
|
|
|
|
432 |
token_lists = list(map(tokenize, segments['Tokens']))
|
433 |
voices = resolve_voices(voice)
|
434 |
speed = clamp_speed(speed)
|
@@ -437,9 +438,6 @@ def lf_generate(segments, voice, speed=1, trim=0, pad_between=0, use_gpu=True, s
|
|
437 |
use_gpu = True
|
438 |
batch_sizes = [89, 55, 34, 21, 13, 8, 5, 3, 2, 1, 1]
|
439 |
i = 0
|
440 |
-
if sk != os.environ['SK']:
|
441 |
-
print('❌', datetime.now(), len(segments), voices, sk)
|
442 |
-
return
|
443 |
while i < len(token_lists):
|
444 |
bs = batch_sizes.pop() if batch_sizes else 100
|
445 |
tokens = token_lists[i:i+bs]
|
|
|
244 |
|
245 |
# Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
|
246 |
def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto', sk=None):
|
247 |
+
sk = os.environ['SK'] if text in sents else sk
|
248 |
+
if sk != os.environ['SK']:
|
249 |
+
return (None, '')
|
250 |
voices = resolve_voices(voice, warn=ps)
|
251 |
ps = ps or phonemize(text, voice)
|
252 |
speed = clamp_speed(speed)
|
253 |
trim = trim if isinstance(trim, int) else 3000
|
254 |
use_gpu = use_gpu if use_gpu in ('auto', False, True) else 'auto'
|
|
|
255 |
tokens = tokenize(ps)
|
256 |
if not tokens:
|
257 |
return (None, '')
|
|
|
259 |
tokens = tokens[:510]
|
260 |
ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
|
261 |
use_gpu = len(ps) > 99 if use_gpu == 'auto' else use_gpu
|
|
|
|
|
|
|
262 |
try:
|
263 |
if use_gpu:
|
264 |
out = forward_gpu(tokens, voices, speed, sk)
|
|
|
428 |
return [(i, *row) for i, row in enumerate(segments)]
|
429 |
|
430 |
def lf_generate(segments, voice, speed=1, trim=0, pad_between=0, use_gpu=True, sk=None):
|
431 |
+
if sk != os.environ['SK']:
|
432 |
+
return
|
433 |
token_lists = list(map(tokenize, segments['Tokens']))
|
434 |
voices = resolve_voices(voice)
|
435 |
speed = clamp_speed(speed)
|
|
|
438 |
use_gpu = True
|
439 |
batch_sizes = [89, 55, 34, 21, 13, 8, 5, 3, 2, 1, 1]
|
440 |
i = 0
|
|
|
|
|
|
|
441 |
while i < len(token_lists):
|
442 |
bs = batch_sizes.pop() if batch_sizes else 100
|
443 |
tokens = token_lists[i:i+bs]
|