lj1995 commited on
Commit
31ba509
·
verified ·
1 Parent(s): 2b68c4c

Update inference_webui.py

Browse files
Files changed (1) hide show
  1. inference_webui.py +44 -35
inference_webui.py CHANGED
@@ -84,15 +84,23 @@ from module.mel_processing import spectrogram_torch
84
  from module.models import SynthesizerTrn
85
  from text import cleaned_text_to_sequence
86
  from text.cleaner import clean_text
87
- from tools.i18n.i18n import I18nAuto, scan_language_list
88
  from tools.my_utils import load_audio
89
 
90
- language=os.environ.get("language","Auto")
91
- language=sys.argv[-1] if sys.argv[-1] in scan_language_list() else language
92
- i18n = I18nAuto(language="Auto")
93
 
94
  # os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' # 确保直接启动推理UI时也能够设置。
95
 
 
 
 
 
 
 
 
 
96
  if torch.cuda.is_available():
97
  device = "cuda"
98
  is_half = True # eval(os.environ.get("is_half", "True")) and torch.cuda.is_available()
@@ -107,26 +115,27 @@ else:
107
  # data=json.loads(f.read())
108
  # i18n_dict[name.split(".json")[0].replace("_","-")]=data
109
  # i18n=gr.I18n(**i18n_dict)
 
110
  dict_language_v1 = {
111
- i18n("中文"): "all_zh", # 全部按中文识别
112
- i18n("英文"): "en", # 全部按英文识别#######不变
113
- i18n("日文"): "all_ja", # 全部按日文识别
114
- i18n("中英混合"): "zh", # 按中英混合识别####不变
115
- i18n("日英混合"): "ja", # 按日英混合识别####不变
116
- i18n("多语种混合"): "auto", # 多语种启动切分识别语种
117
  }
118
  dict_language_v2 = {
119
- i18n("中文"): "all_zh", # 全部按中文识别
120
- i18n("英文"): "en", # 全部按英文识别#######不变
121
- i18n("日文"): "all_ja", # 全部按日文识别
122
- i18n("粤语"): "all_yue", # 全部按中文识别
123
- i18n("韩文"): "all_ko", # 全部按韩文识别
124
- i18n("中英混合"): "zh", # 按中英混合识别####不变
125
- i18n("日英混合"): "ja", # 按日英混合识别####不变
126
- i18n("粤英混合"): "yue", # 按粤英混合识别####不变
127
- i18n("韩英混合"): "ko", # 按韩英混合识别####不变
128
- i18n("多语种混合"): "auto", # 多语种启动切分识别语种
129
- i18n("多语种混合(粤语)"): "auto_yue", # 多语种启动切分识别语种
130
  }
131
  dict_language = dict_language_v1 if version == "v1" else dict_language_v2
132
 
@@ -474,12 +483,12 @@ def get_tts_wav(
474
  prompt_text = prompt_text.strip("\n")
475
  if prompt_text[-1] not in splits:
476
  prompt_text += "。" if prompt_language != "en" else "."
477
- print(i18n("实际输入的参考文本:"), prompt_text)
478
  text = text.strip("\n")
479
  if text[0] not in splits and len(get_first(text)) < 4:
480
  text = "。" + text if text_language != "en" else "." + text
481
 
482
- print(i18n("实际输入的目标文本:"), text)
483
  zero_wav = np.zeros(
484
  int(hps.data.sampling_rate * 0.3),
485
  dtype=np.float16 if is_half == True else np.float32,
@@ -523,7 +532,7 @@ def get_tts_wav(
523
  text = cut5(text)
524
  while "\n\n" in text:
525
  text = text.replace("\n\n", "\n")
526
- print(i18n("实际输入的目标文本(切句后):"), text)
527
  texts = text.split("\n")
528
  texts = process_text(texts)
529
  texts = merge_short_text_in_array(texts, 5)
@@ -539,9 +548,9 @@ def get_tts_wav(
539
  continue
540
  if text[-1] not in splits:
541
  text += "。" if text_language != "en" else "."
542
- print(i18n("实际输入的目标文本(每句):"), text)
543
  phones2, bert2, norm_text2 = get_phones_and_bert(text, text_language, version)
544
- print(i18n("前端处理后的文本(每句):"), norm_text2)
545
  if not ref_free:
546
  bert = torch.cat([bert1, bert2], 1)
547
  all_phoneme_ids = torch.LongTensor(phones1 + phones2).to(device).unsqueeze(0)
@@ -825,12 +834,12 @@ with gr.Blocks(
825
  how_to_cut = gr.Dropdown(
826
  label=i18n("怎么切"),
827
  choices=[
828
- i18n("不切"),
829
- i18n("凑四句一切"),
830
- i18n("凑50字一切"),
831
- i18n("按中文句号。切"),
832
- i18n("按英文句号.切"),
833
- i18n("按标点符号切"),
834
  ],
835
  value=i18n("凑四句一切"),
836
  interactive=True,
@@ -898,9 +907,9 @@ if __name__ == "__main__":
898
  gen = get_tts_wav(
899
  ref_wav_path=file_name,
900
  prompt_text="",
901
- prompt_language=i18n("中文"),
902
  text="犯大吴疆土者,盛必击而破之,犯大吴疆土者,盛必击而破之,犯大吴疆土者,盛必击而破之,犯大吴疆土者,盛必击而破之.你好世界 Love you 世界へ 안녕하세요",
903
- text_language=i18n("多语种混合"),
904
  inp_refs=[],
905
  )
906
  next(gen)
@@ -909,5 +918,5 @@ if __name__ == "__main__":
909
  server_name="0.0.0.0",
910
  inbrowser=True,
911
  show_api=False,
912
- allowed_paths=["/"]#,i18n=i18n
913
  )
 
84
  from module.models import SynthesizerTrn
85
  from text import cleaned_text_to_sequence
86
  from text.cleaner import clean_text
87
+ # from tools.i18n.i18n import I18nAuto, scan_language_list
88
  from tools.my_utils import load_audio
89
 
90
+ # language=os.environ.get("language","Auto")
91
+ # language=sys.argv[-1] if sys.argv[-1] in scan_language_list() else language
92
+ # i18n = I18nAuto(language="Auto")
93
 
94
  # os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' # 确保直接启动推理UI时也能够设置。
95
 
96
+ i18n_dict={}
97
+ json_root="tools/i18n/locale"
98
+ for name in os.listdir(json_root):
99
+ with open("%s/%s"%(json_root,name),"r")as f:
100
+ data=json.loads(f.read())
101
+ i18n_dict[name.split(".json")[0].replace("_","-")]=data
102
+ i18n=gr.I18n(**i18n_dict)
103
+
104
  if torch.cuda.is_available():
105
  device = "cuda"
106
  is_half = True # eval(os.environ.get("is_half", "True")) and torch.cuda.is_available()
 
115
  # data=json.loads(f.read())
116
  # i18n_dict[name.split(".json")[0].replace("_","-")]=data
117
  # i18n=gr.I18n(**i18n_dict)
118
+
119
  dict_language_v1 = {
120
+ i18n("中文").key: "all_zh", # 全部按中文识别
121
+ i18n("英文").key: "en", # 全部按英文识别#######不变
122
+ i18n("日文").key: "all_ja", # 全部按日文识别
123
+ i18n("中英混合").key: "zh", # 按中英混合识别####不变
124
+ i18n("日英混合").key: "ja", # 按日英混合识别####不变
125
+ i18n("多语种混合").key: "auto", # 多语种启动切分识别语种
126
  }
127
  dict_language_v2 = {
128
+ i18n("中文").key: "all_zh", # 全部按中文识别
129
+ i18n("英文").key: "en", # 全部按英文识别#######不变
130
+ i18n("日文").key: "all_ja", # 全部按日文识别
131
+ i18n("粤语").key: "all_yue", # 全部按中文识别
132
+ i18n("韩文").key: "all_ko", # 全部按韩文识别
133
+ i18n("中英混合").key: "zh", # 按中英混合识别####不变
134
+ i18n("日英混合").key: "ja", # 按日英混合识别####不变
135
+ i18n("粤英混合").key: "yue", # 按粤英混合识别####不变
136
+ i18n("韩英混合").key: "ko", # 按韩英混合识别####不变
137
+ i18n("多语种混合").key: "auto", # 多语种启动切分识别语种
138
+ i18n("多语种混合(粤语)").key: "auto_yue", # 多语种启动切分识别语种
139
  }
140
  dict_language = dict_language_v1 if version == "v1" else dict_language_v2
141
 
 
483
  prompt_text = prompt_text.strip("\n")
484
  if prompt_text[-1] not in splits:
485
  prompt_text += "。" if prompt_language != "en" else "."
486
+ print(i18n("实际输入的参考文本:").key, prompt_text)
487
  text = text.strip("\n")
488
  if text[0] not in splits and len(get_first(text)) < 4:
489
  text = "。" + text if text_language != "en" else "." + text
490
 
491
+ print(i18n("实际输入的目标文本:").key, text)
492
  zero_wav = np.zeros(
493
  int(hps.data.sampling_rate * 0.3),
494
  dtype=np.float16 if is_half == True else np.float32,
 
532
  text = cut5(text)
533
  while "\n\n" in text:
534
  text = text.replace("\n\n", "\n")
535
+ print(i18n("实际输入的目标文本(切句后):").key, text)
536
  texts = text.split("\n")
537
  texts = process_text(texts)
538
  texts = merge_short_text_in_array(texts, 5)
 
548
  continue
549
  if text[-1] not in splits:
550
  text += "。" if text_language != "en" else "."
551
+ print(i18n("实际输入的目标文本(每句):").key, text)
552
  phones2, bert2, norm_text2 = get_phones_and_bert(text, text_language, version)
553
+ print(i18n("前端处理后的文本(每句):").key, norm_text2)
554
  if not ref_free:
555
  bert = torch.cat([bert1, bert2], 1)
556
  all_phoneme_ids = torch.LongTensor(phones1 + phones2).to(device).unsqueeze(0)
 
834
  how_to_cut = gr.Dropdown(
835
  label=i18n("怎么切"),
836
  choices=[
837
+ i18n("不切").key,
838
+ i18n("凑四句一切").key,
839
+ i18n("凑50字一切").key,
840
+ i18n("按中文句号。切").key,
841
+ i18n("按英文句号.切").key,
842
+ i18n("按标点符号切").key,
843
  ],
844
  value=i18n("凑四句一切"),
845
  interactive=True,
 
907
  gen = get_tts_wav(
908
  ref_wav_path=file_name,
909
  prompt_text="",
910
+ prompt_language=i18n("中文").key,
911
  text="犯大吴疆土者,盛必击而破之,犯大吴疆土者,盛必击而破之,犯大吴疆土者,盛必击而破之,犯大吴疆土者,盛必击而破之.你好世界 Love you 世界へ 안녕하세요",
912
+ text_language=i18n("多语种混合").key,
913
  inp_refs=[],
914
  )
915
  next(gen)
 
918
  server_name="0.0.0.0",
919
  inbrowser=True,
920
  show_api=False,
921
+ allowed_paths=["/"],i18n=i18n
922
  )