Upload app.py
Browse files
app.py
CHANGED
|
@@ -210,21 +210,22 @@ def forward(tokens, voice, speed, device='cpu'):
|
|
| 210 |
def forward_gpu(tokens, voice, speed):
|
| 211 |
return forward(tokens, voice, speed, device='cuda')
|
| 212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
# Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
|
| 214 |
-
def generate(text, voice, ps=None, speed=1, trim=4000, *args):
|
| 215 |
-
if voice
|
| 216 |
-
voice = 'af'
|
| 217 |
ps = ps or phonemize(text, voice)
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
speed = min(max(0.5, speed), 2)
|
| 222 |
-
if not isinstance(trim, int):
|
| 223 |
-
trim = 4000
|
| 224 |
-
if not args or args[0] not in ('auto', False, True):
|
| 225 |
-
use_gpu = 'auto'
|
| 226 |
-
else:
|
| 227 |
-
use_gpu = args[0]
|
| 228 |
tokens = tokenize(ps)
|
| 229 |
if not tokens:
|
| 230 |
return (None, '')
|
|
|
|
| 210 |
def forward_gpu(tokens, voice, speed):
|
| 211 |
return forward(tokens, voice, speed, device='cuda')
|
| 212 |
|
| 213 |
+
def clamp_speed(speed):
|
| 214 |
+
if not isinstance(speed, float) and not isinstance(speed, int):
|
| 215 |
+
return 1
|
| 216 |
+
elif speed < 0.5:
|
| 217 |
+
return 0.5
|
| 218 |
+
elif speed > 2:
|
| 219 |
+
return 2
|
| 220 |
+
return speed
|
| 221 |
+
|
| 222 |
# Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
|
| 223 |
+
def generate(text, voice='af', ps=None, speed=1, trim=4000, *args):
|
| 224 |
+
voice = voice if voice in VOICES['cpu'] else 'af'
|
|
|
|
| 225 |
ps = ps or phonemize(text, voice)
|
| 226 |
+
speed = clamp_speed(speed)
|
| 227 |
+
trim = trim if isinstance(trim, int) else 4000
|
| 228 |
+
use_gpu = args[0] if args and args[0] in ('auto', False, True) else 'auto'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
tokens = tokenize(ps)
|
| 230 |
if not tokens:
|
| 231 |
return (None, '')
|