Plachta commited on
Commit
40b5ae0
1 Parent(s): 887727d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -67,27 +67,31 @@ _ = net_g.eval()
67
 
68
  _ = utils.load_checkpoint("pretrained_models/G_1153000.pth", net_g, None)
69
 
70
- def infer(text, character, language, duration, noise_scale, noise_scale_w):
71
  # check character & duraction parameter
72
  if language not in languages:
 
73
  return "Error: No such language", None
74
  if character not in characters:
 
75
  return "Error: No such character", None
76
  # check text length
77
  if limitation:
78
- text_len = len(re.sub("\[([A-Z]{2})\]", "", text))
79
  if text_len > max_len:
 
80
  return "Error: Text is too long", None
81
  if text_len == 0:
 
82
  return "Error: Please input text!", None
83
  currentDateAndTime = datetime.now()
84
  show_memory_info(str(currentDateAndTime) + "infer调用前")
85
  if language == '日本語':
86
- pass
87
  elif language == '简体中文':
88
- text = tss.google(text, from_language='zh', to_language='ja')
89
  elif language == 'English':
90
- text = tss.google(text, from_language='en', to_language='ja')
91
  char_id = int(character.split(':')[0])
92
  stn_tst = get_text(text, hps)
93
  with torch.no_grad():
@@ -97,7 +101,10 @@ def infer(text, character, language, duration, noise_scale, noise_scale_w):
97
  audio = net_g.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=noise_scale, noise_scale_w=noise_scale_w,
98
  length_scale=duration)[0][0, 0].data.cpu().float().numpy()
99
  currentDateAndTime = datetime.now()
100
- show_memory_info(str(currentDateAndTime) + "infer调用后")
 
 
 
101
  return (text, (22050, audio))
102
 
103
  if __name__ == "__main__":
 
67
 
68
  _ = utils.load_checkpoint("pretrained_models/G_1153000.pth", net_g, None)
69
 
70
+ def infer(text_raw, character, language, duration, noise_scale, noise_scale_w):
71
  # check character & duraction parameter
72
  if language not in languages:
73
+ print("Error: No such language\n")
74
  return "Error: No such language", None
75
  if character not in characters:
76
+ print("Error: No such character\n")
77
  return "Error: No such character", None
78
  # check text length
79
  if limitation:
80
+ text_len = len(re.sub("\[([A-Z]{2})\]", "", text_raw))
81
  if text_len > max_len:
82
+ print(f"Refused: Text too long ({text_len}).")
83
  return "Error: Text is too long", None
84
  if text_len == 0:
85
+ print("Refused: Text length is zero.")
86
  return "Error: Please input text!", None
87
  currentDateAndTime = datetime.now()
88
  show_memory_info(str(currentDateAndTime) + "infer调用前")
89
  if language == '日本語':
90
+ text = text_raw
91
  elif language == '简体中文':
92
+ text = tss.google(text_raw, from_language='zh', to_language='ja')
93
  elif language == 'English':
94
+ text = tss.google(text_raw, from_language='en', to_language='ja')
95
  char_id = int(character.split(':')[0])
96
  stn_tst = get_text(text, hps)
97
  with torch.no_grad():
 
101
  audio = net_g.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=noise_scale, noise_scale_w=noise_scale_w,
102
  length_scale=duration)[0][0, 0].data.cpu().float().numpy()
103
  currentDateAndTime = datetime.now()
104
+ print(f"inference successful: {text}\n")
105
+ if language != '日本語':
106
+ print(f"translate from {language}: {text_raw}")
107
+ show_memory_info(str(currentDateAndTime) + " infer调用后")
108
  return (text, (22050, audio))
109
 
110
  if __name__ == "__main__":