support sovits v2Pro v2ProPlus

support sovits v2Pro v2ProPlus
This commit is contained in:
RVC-Boss
2025-06-04 15:15:54 +08:00
committed by GitHub
parent 663c3cc6fc
commit b7c0c5ca87
4 changed files with 640 additions and 133 deletions

241
webui.py
View File

@@ -1,10 +1,6 @@
import os
import sys
if len(sys.argv) == 1:
sys.argv.append("v2")
version = "v1" if sys.argv[1] == "v1" else "v2"
os.environ["version"] = version
os.environ["version"] = version="v2Pro"
now_dir = os.getcwd()
sys.path.insert(0, now_dir)
import warnings
@@ -63,7 +59,11 @@ for site_packages_root in site_packages_roots:
import shutil
import subprocess
from subprocess import Popen
from tools.i18n.i18n import I18nAuto, scan_language_list
language = sys.argv[-1] if sys.argv[-1] in scan_language_list() else "Auto"
os.environ["language"] = language
i18n = I18nAuto(language=language)
from config import (
exp_root,
infer_device,
@@ -76,11 +76,6 @@ from config import (
webui_port_uvr5,
)
from tools import my_utils
from tools.i18n.i18n import I18nAuto, scan_language_list
language = sys.argv[-1] if sys.argv[-1] in scan_language_list() else "Auto"
os.environ["language"] = language
i18n = I18nAuto(language=language)
from multiprocessing import cpu_count
from tools.my_utils import check_details, check_for_existance
@@ -232,86 +227,32 @@ def fix_gpu_numbers(inputs):
return inputs
pretrained_sovits_name = [
"GPT_SoVITS/pretrained_models/s2G488k.pth",
"GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s2G2333k.pth",
"GPT_SoVITS/pretrained_models/s2Gv3.pth",
"GPT_SoVITS/pretrained_models/gsv-v4-pretrained/s2Gv4.pth",
]
pretrained_gpt_name = [
"GPT_SoVITS/pretrained_models/s1bert25hz-2kh-longer-epoch=68e-step=50232.ckpt",
"GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s1bert25hz-5kh-longer-epoch=12-step=369668.ckpt",
"GPT_SoVITS/pretrained_models/s1v3.ckpt",
"GPT_SoVITS/pretrained_models/s1v3.ckpt",
]
from config import pretrained_sovits_name,pretrained_gpt_name
pretrained_model_list = (
pretrained_sovits_name[int(version[-1]) - 1],
pretrained_sovits_name[int(version[-1]) - 1].replace("s2G", "s2D"),
pretrained_gpt_name[int(version[-1]) - 1],
"GPT_SoVITS/pretrained_models/chinese-roberta-wwm-ext-large",
"GPT_SoVITS/pretrained_models/chinese-hubert-base",
)
def check_pretrained_is_exist(version):
pretrained_model_list = (
pretrained_sovits_name[version],
pretrained_sovits_name[version].replace("s2G", "s2D"),
pretrained_gpt_name[version],
"GPT_SoVITS/pretrained_models/chinese-roberta-wwm-ext-large",
"GPT_SoVITS/pretrained_models/chinese-hubert-base",
)
_ = ""
for i in pretrained_model_list:
if "s2Dv3" not in i and "s2Dv4" not in i and os.path.exists(i) == False:
_ += f"\n {i}"
if _:
print("warning: ", i18n("以下模型不存在:") + _)
check_pretrained_is_exist(version)
for key in pretrained_sovits_name.keys():
if os.path.exists(pretrained_sovits_name[key])==False:pretrained_sovits_name[key]=""
for key in pretrained_gpt_name.keys():
if os.path.exists(pretrained_gpt_name[key])==False:pretrained_gpt_name[key]=""
_ = ""
for i in pretrained_model_list:
if "s2Dv3" not in i and os.path.exists(i) == False:
_ += f"\n {i}"
if _:
print("warning: ", i18n("以下模型不存在:") + _)
_ = [[], []]
for i in range(4):
if os.path.exists(pretrained_gpt_name[i]):
_[0].append(pretrained_gpt_name[i])
else:
_[0].append("") ##没有下pretrained模型的说不定他们是想自己从零训底模呢
if os.path.exists(pretrained_sovits_name[i]):
_[-1].append(pretrained_sovits_name[i])
else:
_[-1].append("")
pretrained_gpt_name, pretrained_sovits_name = _
SoVITS_weight_root = ["SoVITS_weights", "SoVITS_weights_v2", "SoVITS_weights_v3", "SoVITS_weights_v4"]
GPT_weight_root = ["GPT_weights", "GPT_weights_v2", "GPT_weights_v3", "GPT_weights_v4"]
from config import SoVITS_weight_root,GPT_weight_root,get_weights_names,change_choices,SoVITS_weight_version2root,GPT_weight_version2root
for root in SoVITS_weight_root + GPT_weight_root:
os.makedirs(root, exist_ok=True)
def get_weights_names():
SoVITS_names = [name for name in pretrained_sovits_name if name != ""]
for path in SoVITS_weight_root:
for name in os.listdir(path):
if name.endswith(".pth"):
SoVITS_names.append("%s/%s" % (path, name))
GPT_names = [name for name in pretrained_gpt_name if name != ""]
for path in GPT_weight_root:
for name in os.listdir(path):
if name.endswith(".ckpt"):
GPT_names.append("%s/%s" % (path, name))
return SoVITS_names, GPT_names
SoVITS_names, GPT_names = get_weights_names()
for path in SoVITS_weight_root + GPT_weight_root:
os.makedirs(path, exist_ok=True)
def custom_sort_key(s):
# 使用正则表达式提取字符串中的数字部分和非数字部分
parts = re.split("(\d+)", s)
# 将数字部分转换为整数,非数字部分保持不变
parts = [int(part) if part.isdigit() else part for part in parts]
return parts
def change_choices():
SoVITS_names, GPT_names = get_weights_names()
return {"choices": sorted(SoVITS_names, key=custom_sort_key), "__type__": "update"}, {
"choices": sorted(GPT_names, key=custom_sort_key),
"__type__": "update",
}
p_label = None
p_uvr5 = None
@@ -450,8 +391,8 @@ def change_tts_inference(bert_path, cnhubert_base_path, gpu_number, gpt_path, so
# if version=="v3":
# cmd = '"%s" GPT_SoVITS/inference_webui.py "%s"'%(python_exec, language)
if p_tts_inference is None:
os.environ["gpt_path"] = gpt_path if "/" in gpt_path else "%s/%s" % (GPT_weight_root, gpt_path)
os.environ["sovits_path"] = sovits_path if "/" in sovits_path else "%s/%s" % (SoVITS_weight_root, sovits_path)
os.environ["gpt_path"] = gpt_path
os.environ["sovits_path"] = sovits_path
os.environ["cnhubert_base_path"] = cnhubert_base_path
os.environ["bert_path"] = bert_path
os.environ["_CUDA_VISIBLE_DEVICES"] = fix_gpu_number(gpu_number)
@@ -599,6 +540,7 @@ process_name_sovits = i18n("SoVITS训练")
def open1Ba(
version,
batch_size,
total_epoch,
exp_name,
@@ -614,7 +556,8 @@ def open1Ba(
):
global p_train_SoVITS
if p_train_SoVITS == None:
with open("GPT_SoVITS/configs/s2.json") as f:
config_file="GPT_SoVITS/configs/s2.json" if version not in {"v2Pro","v2ProPlus"}else f"GPT_SoVITS/configs/s2{version}.json"
with open(config_file) as f:
data = f.read()
data = json.loads(data)
s2_dir = "%s/%s" % (exp_root, exp_name)
@@ -637,13 +580,13 @@ def open1Ba(
data["train"]["lora_rank"] = lora_rank
data["model"]["version"] = version
data["data"]["exp_dir"] = data["s2_ckpt_dir"] = s2_dir
data["save_weight_dir"] = SoVITS_weight_root[int(version[-1]) - 1]
data["save_weight_dir"] = SoVITS_weight_version2root[version]
data["name"] = exp_name
data["version"] = version
tmp_config_path = "%s/tmp_s2.json" % tmp
with open(tmp_config_path, "w") as f:
f.write(json.dumps(data))
if version in ["v1", "v2"]:
if version in ["v1", "v2","v2Pro","v2ProPlus"]:
cmd = '"%s" -s GPT_SoVITS/s2_train.py --config "%s"' % (python_exec, tmp_config_path)
else:
cmd = '"%s" -s GPT_SoVITS/s2_train_v3_lora.py --config "%s"' % (python_exec, tmp_config_path)
@@ -724,7 +667,7 @@ def open1Bb(
data["train"]["if_save_every_weights"] = if_save_every_weights
data["train"]["if_save_latest"] = if_save_latest
data["train"]["if_dpo"] = if_dpo
data["train"]["half_weights_save_dir"] = GPT_weight_root[int(version[-1]) - 1]
data["train"]["half_weights_save_dir"] = GPT_weight_version2root[version]
data["train"]["exp_name"] = exp_name
data["train_semantic_path"] = "%s/6-name2semantic.tsv" % s1_dir
data["train_phoneme_path"] = "%s/2-name2text.txt" % s1_dir
@@ -964,12 +907,10 @@ def close1a():
{"__type__": "update", "visible": False},
)
sv_path="GPT_SoVITS\pretrained_models\sv\pretrained_eres2netv2w24s4ep4.ckpt"
ps1b = []
process_name_1b = i18n("语音自监督特征提取")
def open1b(inp_text, inp_wav_dir, exp_name, gpu_numbers, ssl_pretrained_dir):
def open1b(version,inp_text, inp_wav_dir, exp_name, gpu_numbers, ssl_pretrained_dir):
global ps1b
inp_text = my_utils.clean_path(inp_text)
inp_wav_dir = my_utils.clean_path(inp_wav_dir)
@@ -982,6 +923,7 @@ def open1b(inp_text, inp_wav_dir, exp_name, gpu_numbers, ssl_pretrained_dir):
"exp_name": exp_name,
"opt_dir": "%s/%s" % (exp_root, exp_name),
"cnhubert_base_dir": ssl_pretrained_dir,
"sv_path": sv_path,
"is_half": str(is_half),
}
gpu_names = gpu_numbers.split("-")
@@ -1007,6 +949,23 @@ def open1b(inp_text, inp_wav_dir, exp_name, gpu_numbers, ssl_pretrained_dir):
for p in ps1b:
p.wait()
ps1b = []
if "Pro"in version:
for i_part in range(all_parts):
config.update(
{
"i_part": str(i_part),
"all_parts": str(all_parts),
"_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_names[i_part]),
}
)
os.environ.update(config)
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/2-get-sv.py' % python_exec
print(cmd)
p = Popen(cmd, shell=True)
ps1b.append(p)
for p in ps1b:
p.wait()
ps1b = []
yield (
process_info(process_name_1b, "finish"),
{"__type__": "update", "visible": True},
@@ -1040,19 +999,20 @@ ps1c = []
process_name_1c = i18n("语义Token提取")
def open1c(inp_text, exp_name, gpu_numbers, pretrained_s2G_path):
def open1c(version,inp_text,inp_wav_dir, exp_name, gpu_numbers, pretrained_s2G_path):
global ps1c
inp_text = my_utils.clean_path(inp_text)
if check_for_existance([inp_text, ""], is_dataset_processing=True):
check_details([inp_text, ""], is_dataset_processing=True)
if check_for_existance([inp_text, inp_wav_dir], is_dataset_processing=True):
check_details([inp_text, inp_wav_dir], is_dataset_processing=True)
if ps1c == []:
opt_dir = "%s/%s" % (exp_root, exp_name)
config_file="GPT_SoVITS/configs/s2.json" if version not in {"v2Pro","v2ProPlus"}else f"GPT_SoVITS/configs/s2{version}.json"
config = {
"inp_text": inp_text,
"exp_name": exp_name,
"opt_dir": opt_dir,
"pretrained_s2G": pretrained_s2G_path,
"s2config_path": "GPT_SoVITS/configs/s2.json",
"s2config_path": config_file,
"is_half": str(is_half),
}
gpu_names = gpu_numbers.split("-")
@@ -1121,6 +1081,7 @@ process_name_1abc = i18n("训练集格式化一键三连")
def open1abc(
version,
inp_text,
inp_wav_dir,
exp_name,
@@ -1198,6 +1159,7 @@ def open1abc(
"exp_name": exp_name,
"opt_dir": opt_dir,
"cnhubert_base_dir": ssl_pretrained_dir,
"sv_path": sv_path,
}
gpu_names = gpu_numbers1Ba.split("-")
all_parts = len(gpu_names)
@@ -1221,23 +1183,41 @@ def open1abc(
)
for p in ps1abc:
p.wait()
ps1abc=[]
if "Pro" in version:
for i_part in range(all_parts):
config.update(
{
"i_part": str(i_part),
"all_parts": str(all_parts),
"_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_names[i_part]),
}
)
os.environ.update(config)
cmd = '"%s" -s GPT_SoVITS/prepare_datasets/2-get-sv.py' % python_exec
print(cmd)
p = Popen(cmd, shell=True)
ps1abc.append(p)
for p in ps1abc:
p.wait()
ps1abc = []
yield (
i18n("进度") + ": 1A-Done, 1B-Done",
{"__type__": "update", "visible": False},
{"__type__": "update", "visible": True},
)
ps1abc = []
#############################1c
path_semantic = "%s/6-name2semantic.tsv" % opt_dir
if os.path.exists(path_semantic) == False or (
os.path.exists(path_semantic) == True and os.path.getsize(path_semantic) < 31
):
config_file = "GPT_SoVITS/configs/s2.json" if version not in {"v2Pro", "v2ProPlus"} else f"GPT_SoVITS/configs/s2{version}.json"
config = {
"inp_text": inp_text,
"exp_name": exp_name,
"opt_dir": opt_dir,
"pretrained_s2G": pretrained_s2G_path,
"s2config_path": "GPT_SoVITS/configs/s2.json",
"s2config_path": config_file,
}
gpu_names = gpu_numbers1c.split("-")
all_parts = len(gpu_names)
@@ -1317,17 +1297,17 @@ def switch_version(version_):
os.environ["version"] = version_
global version
version = version_
if pretrained_sovits_name[int(version[-1]) - 1] != "" and pretrained_gpt_name[int(version[-1]) - 1] != "":
if pretrained_sovits_name[version] != "" and pretrained_gpt_name[version] != "":
...
else:
gr.Warning(i18n("未下载模型") + ": " + version.upper())
set_default()
return (
{"__type__": "update", "value": pretrained_sovits_name[int(version[-1]) - 1]},
{"__type__": "update", "value": pretrained_sovits_name[int(version[-1]) - 1].replace("s2G", "s2D")},
{"__type__": "update", "value": pretrained_gpt_name[int(version[-1]) - 1]},
{"__type__": "update", "value": pretrained_gpt_name[int(version[-1]) - 1]},
{"__type__": "update", "value": pretrained_sovits_name[int(version[-1]) - 1]},
{"__type__": "update", "value": pretrained_sovits_name[version]},
{"__type__": "update", "value": pretrained_sovits_name[version].replace("s2G", "s2D")},
{"__type__": "update", "value": pretrained_gpt_name[version]},
{"__type__": "update", "value": pretrained_gpt_name[version]},
{"__type__": "update", "value": pretrained_sovits_name[version]},
{"__type__": "update", "value": default_batch_size, "maximum": default_max_batch_size},
{"__type__": "update", "value": default_sovits_epoch, "maximum": max_sovits_epoch},
{"__type__": "update", "value": default_sovits_save_every_epoch, "maximum": max_sovits_save_every_epoch},
@@ -1357,10 +1337,7 @@ def sync(text):
with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False) as app:
gr.Markdown(
value=i18n("本软件以MIT协议开源, 作者不对软件具备任何控制力, 使用软件者、传播软件导出的声音者自负全责.")
+ "<br>"
+ i18n("如不认可该条款, 则不能使用或引用软件包内任何代码和文件. 详见根目录LICENSE.")
)
gr.Markdown(value=i18n("中文教程文档") + ": " + "https://www.yuque.com/baicaigongchang1145haoyuangong/ib3g1e")
+ i18n("如不认可该条款, 则不能使用或引用软件包内任何代码和文件. 详见根目录LICENSE.")+ "<br>"+i18n("中文教程文档") + ": " + "https://www.yuque.com/baicaigongchang1145haoyuangong/ib3g1e")
with gr.Tabs():
with gr.TabItem("0-" + i18n("前置数据集获取工具")): # 提前随机切片防止uvr5爆内存->uvr5->slicer->asr->打标
@@ -1419,8 +1396,8 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False) as app:
value=process_info(process_name_slice, "close"), variant="primary", visible=False
)
gr.Markdown(value="0bb-" + i18n("语音降噪工具")+i18n("(不稳定,先别用,可能劣化模型效果!)"))
with gr.Row():
# gr.Markdown(value="0bb-" + i18n("语音降噪工具")+i18n("(不稳定,先别用,可能劣化模型效果!)"))
with gr.Row(visible=False):
with gr.Column(scale=3):
with gr.Row():
denoise_input_dir = gr.Textbox(label=i18n("输入文件夹路径"), value="")
@@ -1512,33 +1489,33 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False) as app:
with gr.TabItem(i18n("1-GPT-SoVITS-TTS")):
with gr.Row():
with gr.Row():
exp_name = gr.Textbox(label=i18n("*实验/模型名"), value="xxx", interactive=True)
gpu_info = gr.Textbox(label=i18n("显卡信息"), value=gpu_info, visible=True, interactive=False)
version_checkbox = gr.Radio(label=i18n("版本"), value=version, choices=["v1", "v2", "v4"]) # , "v3"
with gr.Row():
exp_name = gr.Textbox(label=i18n("*实验/模型名"), value="xxx", interactive=True,scale=3,)
gpu_info = gr.Textbox(label=i18n("显卡信息"), value=gpu_info, visible=True, interactive=False,scale=5,)
version_checkbox = gr.Radio(label=i18n("训练模型的版本"), value=version, choices=["v1","v2", "v4", "v2Pro", "v2ProPlus"],scale=5,)
# version_checkbox = gr.Radio(label=i18n("训练模型的版本"), value=version, choices=["v2", "v4", "v2Pro", "v2ProPlus", "v2ProMax"],scale=5,)
pretrained_s2G = gr.Textbox(
label=i18n("预训练SoVITS-G模型路径"),
value=pretrained_sovits_name[int(version[-1]) - 1],
value=pretrained_sovits_name[version],
interactive=True,
lines=2,
max_lines=3,
scale=9,
scale=5,
)
pretrained_s2D = gr.Textbox(
label=i18n("预训练SoVITS-D模型路径"),
value=pretrained_sovits_name[int(version[-1]) - 1].replace("s2G", "s2D"),
value=pretrained_sovits_name[version].replace("s2G", "s2D"),
interactive=True,
lines=2,
max_lines=3,
scale=9,
scale=5,
)
pretrained_s1 = gr.Textbox(
label=i18n("预训练GPT模型路径"),
value=pretrained_gpt_name[int(version[-1]) - 1],
value=pretrained_gpt_name[version],
interactive=True,
lines=2,
max_lines=3,
scale=10,
scale=5,
)
with gr.TabItem("1A-" + i18n("训练集格式化工具")):
@@ -1623,7 +1600,7 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False) as app:
with gr.Row():
pretrained_s2G_ = gr.Textbox(
label=i18n("预训练SoVITS-G模型路径"),
value=pretrained_sovits_name[int(version[-1]) - 1],
value=pretrained_sovits_name[version],
interactive=False,
lines=2,
)
@@ -1688,17 +1665,18 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False) as app:
button1a_close.click(close1a, [], [info1a, button1a_open, button1a_close])
button1b_open.click(
open1b,
[inp_text, inp_wav_dir, exp_name, gpu_numbers1Ba, cnhubert_base_dir],
[version_checkbox,inp_text, inp_wav_dir, exp_name, gpu_numbers1Ba, cnhubert_base_dir],
[info1b, button1b_open, button1b_close],
)
button1b_close.click(close1b, [], [info1b, button1b_open, button1b_close])
button1c_open.click(
open1c, [inp_text, exp_name, gpu_numbers1c, pretrained_s2G], [info1c, button1c_open, button1c_close]
open1c, [version_checkbox,inp_text, inp_wav_dir,exp_name, gpu_numbers1c, pretrained_s2G], [info1c, button1c_open, button1c_close]
)
button1c_close.click(close1c, [], [info1c, button1c_open, button1c_close])
button1abc_open.click(
open1abc,
[
version_checkbox,
inp_text,
inp_wav_dir,
exp_name,
@@ -1862,21 +1840,21 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False) as app:
with gr.TabItem("1C-" + i18n("推理")):
gr.Markdown(
value=i18n(
"选择训练完存放在SoVITS_weights和GPT_weights下的模型。默认的个是底模体验5秒Zero Shot TTS用。"
"选择训练完存放在SoVITS_weights和GPT_weights下的模型。默认的个是底模体验5秒Zero Shot TTS不训练推理用。"
)
)
with gr.Row():
with gr.Row():
GPT_dropdown = gr.Dropdown(
label=i18n("GPT模型列表"),
choices=sorted(GPT_names, key=custom_sort_key),
value=pretrained_gpt_name[0],
choices=GPT_names,
value=GPT_names[-1],
interactive=True,
)
SoVITS_dropdown = gr.Dropdown(
label=i18n("SoVITS模型列表"),
choices=sorted(SoVITS_names, key=custom_sort_key),
value=pretrained_sovits_name[0],
choices=SoVITS_names,
value=SoVITS_names[0],
interactive=True,
)
with gr.Row():
@@ -1924,6 +1902,7 @@ with gr.Blocks(title="GPT-SoVITS WebUI", analytics_enabled=False) as app:
button1Ba_open.click(
open1Ba,
[
version_checkbox,
batch_size,
total_epoch,
exp_name,