Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,25 @@ limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in h
|
|
36 |
|
37 |
def create_tts_fn(model, hps, speaker_ids):
|
38 |
def tts_fn(text, speaker, language, speed, is_symbol):
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
return tts_fn
|
42 |
|
@@ -47,7 +65,7 @@ def create_vc_fn(model, hps, speaker_ids):
|
|
47 |
return "You need to upload an audio", None
|
48 |
sampling_rate, audio = input_audio
|
49 |
duration = audio.shape[0] / sampling_rate
|
50 |
-
if limitation and duration >
|
51 |
return "Error: Audio is too long", None
|
52 |
original_speaker_id = speaker_ids[original_speaker]
|
53 |
target_speaker_id = speaker_ids[target_speaker]
|
@@ -210,9 +228,7 @@ if __name__ == "__main__":
|
|
210 |
text_input.selectionEnd = startPos + symbols[i].length;
|
211 |
text_input.blur();
|
212 |
window.scrollTo(x, y);
|
213 |
-
|
214 |
text = text_input.value;
|
215 |
-
|
216 |
return text;
|
217 |
}}""")
|
218 |
# select character
|
|
|
36 |
|
37 |
def create_tts_fn(model, hps, speaker_ids):
|
38 |
def tts_fn(text, speaker, language, speed, is_symbol):
|
39 |
+
if limitation:
|
40 |
+
text_len = len(re.sub("\[([A-Z]{2})\]", "", text))
|
41 |
+
max_len = 150
|
42 |
+
if is_symbol:
|
43 |
+
max_len *= 3
|
44 |
+
if text_len > max_len:
|
45 |
+
return "Error: Text is too long", None
|
46 |
+
if language is not None:
|
47 |
+
text = language_marks[language] + text + language_marks[language]
|
48 |
+
speaker_id = speaker_ids[speaker]
|
49 |
+
stn_tst = get_text(text, hps, is_symbol)
|
50 |
+
with no_grad():
|
51 |
+
x_tst = stn_tst.unsqueeze(0)
|
52 |
+
x_tst_lengths = LongTensor([stn_tst.size(0)])
|
53 |
+
sid = LongTensor([speaker_id])
|
54 |
+
audio = model.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=.667, noise_scale_w=0.8,
|
55 |
+
length_scale=1.0 / speed)[0][0, 0].data.cpu().float().numpy()
|
56 |
+
del stn_tst, x_tst, x_tst_lengths, sid
|
57 |
+
return "Success", (hps.data.sampling_rate, audio)
|
58 |
|
59 |
return tts_fn
|
60 |
|
|
|
65 |
return "You need to upload an audio", None
|
66 |
sampling_rate, audio = input_audio
|
67 |
duration = audio.shape[0] / sampling_rate
|
68 |
+
if limitation and duration > 30:
|
69 |
return "Error: Audio is too long", None
|
70 |
original_speaker_id = speaker_ids[original_speaker]
|
71 |
target_speaker_id = speaker_ids[target_speaker]
|
|
|
228 |
text_input.selectionEnd = startPos + symbols[i].length;
|
229 |
text_input.blur();
|
230 |
window.scrollTo(x, y);
|
|
|
231 |
text = text_input.value;
|
|
|
232 |
return text;
|
233 |
}}""")
|
234 |
# select character
|