ORI-Muchim commited on
Commit
f229280
1 Parent(s): e8751c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -25,24 +25,21 @@ def get_text(text, hps, is_phoneme):
25
 
26
 
27
  def create_tts_fn(model, hps, speaker_ids):
28
- def tts_fn(text, speaker, speed, is_phoneme):
29
  if limitation:
30
- text_len = len(text)
31
- max_len = 100
32
- if is_phoneme:
33
  max_len *= 3
34
- else:
35
- if len(hps.data.text_cleaners) > 0 and hps.data.text_cleaners[0] == "zh_ja_mixture_cleaners":
36
- text_len = len(re.sub("(\[ZH\]|\[JA\])", "", text))
37
  if text_len > max_len:
38
  return "Error: Text is too long", None
39
 
40
  speaker_id = speaker_ids[speaker]
41
- stn_tst = get_text(text, hps, is_phoneme)
42
  with no_grad():
43
- x_tst = stn_tst.unsqueeze(0)
44
- x_tst_lengths = LongTensor([stn_tst.size(0)])
45
- sid = LongTensor([speaker_id])
46
  audio = model.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=.667, noise_scale_w=0.8,
47
  length_scale=1.0 / speed)[0][0, 0].data.cpu().float().numpy()
48
  del stn_tst, x_tst, x_tst_lengths, sid
@@ -51,9 +48,6 @@ def create_tts_fn(model, hps, speaker_ids):
51
  return tts_fn
52
 
53
 
54
-
55
-
56
-
57
  def create_to_phoneme_fn(hps):
58
  def to_phoneme_fn(text):
59
  return _clean_text(text, hps.data.text_cleaners) if text != "" else ""
 
25
 
26
 
27
  def create_tts_fn(model, hps, speaker_ids):
28
+ def tts_fn(text, speaker, speed, is_symbol):
29
  if limitation:
30
+ text_len = len(re.sub("\[([A-Z]{2})\]", "", text))
31
+ max_len = 150
32
+ if is_symbol:
33
  max_len *= 3
 
 
 
34
  if text_len > max_len:
35
  return "Error: Text is too long", None
36
 
37
  speaker_id = speaker_ids[speaker]
38
+ stn_tst = get_text(text, hps, is_symbol)
39
  with no_grad():
40
+ x_tst = stn_tst.unsqueeze(0).to(device)
41
+ x_tst_lengths = LongTensor([stn_tst.size(0)]).to(device)
42
+ sid = LongTensor([speaker_id]).to(device)
43
  audio = model.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=.667, noise_scale_w=0.8,
44
  length_scale=1.0 / speed)[0][0, 0].data.cpu().float().numpy()
45
  del stn_tst, x_tst, x_tst_lengths, sid
 
48
  return tts_fn
49
 
50
 
 
 
 
51
  def create_to_phoneme_fn(hps):
52
  def to_phoneme_fn(text):
53
  return _clean_text(text, hps.data.text_cleaners) if text != "" else ""