From 35fac290ba937d032f9b635a14abf667037a1dcb Mon Sep 17 00:00:00 2001 From: Spr_Aachen <2835946988@qq.com> Date: Mon, 10 Nov 2025 15:00:00 +0800 Subject: [PATCH] Improve G2PWPinyin model handling - Add 'bert_pretrained_dir' environment variable as the highest priority for model_source - Replace redundant g2pw initialization in chinese2.py with import from download.py - Remove unused 'parent_directory' variable --- GPT_SoVITS/download.py | 2 +- GPT_SoVITS/text/chinese2.py | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/GPT_SoVITS/download.py b/GPT_SoVITS/download.py index fc4ead63..aa344ba1 100644 --- a/GPT_SoVITS/download.py +++ b/GPT_SoVITS/download.py @@ -7,7 +7,7 @@ from text.g2pw import G2PWPinyin g2pw = G2PWPinyin( model_dir="GPT_SoVITS/text/G2PWModel", - model_source="GPT_SoVITS/pretrained_models/chinese-roberta-wwm-ext-large", + model_source=os.environ.get("bert_pretrained_dir") or os.environ.get("bert_path") or "GPT_SoVITS/pretrained_models/chinese-roberta-wwm-ext-large", v_to_u=False, neutral_tone_with_five=True, ) diff --git a/GPT_SoVITS/text/chinese2.py b/GPT_SoVITS/text/chinese2.py index dcce0d96..9ea83b97 100644 --- a/GPT_SoVITS/text/chinese2.py +++ b/GPT_SoVITS/text/chinese2.py @@ -28,15 +28,8 @@ import jieba_fast.posseg as psg is_g2pw = True # True if is_g2pw_str.lower() == 'true' else False if is_g2pw: # print("当前使用g2pw进行拼音推理") - from text.g2pw import G2PWPinyin, correct_pronunciation - - parent_directory = os.path.dirname(current_file_path) - g2pw = G2PWPinyin( - model_dir="GPT_SoVITS/text/G2PWModel", - model_source=os.environ.get("bert_path", "GPT_SoVITS/pretrained_models/chinese-roberta-wwm-ext-large"), - v_to_u=False, - neutral_tone_with_five=True, - ) + from text.g2pw import correct_pronunciation + from download import g2pw rep_map = { ":": ",",