ORI-Muchim commited on
Commit
3a27cd1
1 Parent(s): b3f62b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -25,21 +25,24 @@ 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_symbol):
29
  if limitation:
30
- text_len = len(re.sub("\[([A-Z]{2})\]", "", text))
31
  max_len = 100
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
 
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