Spaces:
No application file
No application file
Create rebuild.py
Browse files- rebuild.py +161 -0
rebuild.py
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
import os
|
3 |
+
|
4 |
+
# os.system("wget -P cvec/ https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt")
|
5 |
+
import gradio as gr
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
|
8 |
+
from configs.config import Config
|
9 |
+
from i18n.i18n import I18nAuto
|
10 |
+
from infer.modules.vc.modules import VC
|
11 |
+
|
12 |
+
logging.getLogger("numba").setLevel(logging.WARNING)
|
13 |
+
logging.getLogger("markdown_it").setLevel(logging.WARNING)
|
14 |
+
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
15 |
+
logging.getLogger("matplotlib").setLevel(logging.WARNING)
|
16 |
+
logger = logging.getLogger(__name__)
|
17 |
+
|
18 |
+
i18n = I18nAuto()
|
19 |
+
logger.info(i18n)
|
20 |
+
|
21 |
+
load_dotenv()
|
22 |
+
config = Config()
|
23 |
+
vc = VC(config)
|
24 |
+
|
25 |
+
weight_root = os.getenv("weight_root")
|
26 |
+
weight_uvr5_root = os.getenv("weight_uvr5_root")
|
27 |
+
index_root = os.getenv("index_root")
|
28 |
+
names = []
|
29 |
+
hubert_model = None
|
30 |
+
for name in os.listdir(weight_root):
|
31 |
+
if name.endswith(".pth"):
|
32 |
+
names.append(name)
|
33 |
+
index_paths = []
|
34 |
+
for root, dirs, files in os.walk(index_root, topdown=False):
|
35 |
+
for name in files:
|
36 |
+
if name.endswith(".index") and "trained" not in name:
|
37 |
+
index_paths.append("%s/%s" % (root, name))
|
38 |
+
|
39 |
+
|
40 |
+
app = gr.Blocks()
|
41 |
+
with app:
|
42 |
+
with gr.Tabs():
|
43 |
+
with gr.TabItem("在线demo"):
|
44 |
+
gr.Markdown(
|
45 |
+
value="""
|
46 |
+
RVC 在线demo
|
47 |
+
"""
|
48 |
+
)
|
49 |
+
sid = gr.Dropdown(label=i18n("推理音色"), choices=sorted(names))
|
50 |
+
with gr.Column():
|
51 |
+
spk_item = gr.Slider(
|
52 |
+
minimum=0,
|
53 |
+
maximum=2333,
|
54 |
+
step=1,
|
55 |
+
label=i18n("请选择说话人id"),
|
56 |
+
value=0,
|
57 |
+
visible=False,
|
58 |
+
interactive=True,
|
59 |
+
)
|
60 |
+
sid.change(fn=vc.get_vc, inputs=[sid], outputs=[spk_item])
|
61 |
+
gr.Markdown(
|
62 |
+
value=i18n(
|
63 |
+
"男转女推荐+12key, 女转男推荐-12key, 如果音域爆炸导致音色失真也可以自己调整到合适音域. "
|
64 |
+
)
|
65 |
+
)
|
66 |
+
vc_input3 = gr.Audio(label="上传音频(长度小于90秒)")
|
67 |
+
vc_transform0 = gr.Number(
|
68 |
+
label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
|
69 |
+
)
|
70 |
+
f0method0 = gr.Radio(
|
71 |
+
label=i18n(
|
72 |
+
"选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU"
|
73 |
+
),
|
74 |
+
choices=["pm", "harvest", "crepe", "rmvpe"],
|
75 |
+
value="pm",
|
76 |
+
interactive=True,
|
77 |
+
)
|
78 |
+
filter_radius0 = gr.Slider(
|
79 |
+
minimum=0,
|
80 |
+
maximum=7,
|
81 |
+
label=i18n(
|
82 |
+
">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"
|
83 |
+
),
|
84 |
+
value=3,
|
85 |
+
step=1,
|
86 |
+
interactive=True,
|
87 |
+
)
|
88 |
+
with gr.Column():
|
89 |
+
file_index1 = gr.Textbox(
|
90 |
+
label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
|
91 |
+
value="",
|
92 |
+
interactive=False,
|
93 |
+
visible=False,
|
94 |
+
)
|
95 |
+
file_index2 = gr.Dropdown(
|
96 |
+
label=i18n("自动检测index路径,下拉式选择(dropdown)"),
|
97 |
+
choices=sorted(index_paths),
|
98 |
+
interactive=True,
|
99 |
+
)
|
100 |
+
index_rate1 = gr.Slider(
|
101 |
+
minimum=0,
|
102 |
+
maximum=1,
|
103 |
+
label=i18n("检索特征占比"),
|
104 |
+
value=0.88,
|
105 |
+
interactive=True,
|
106 |
+
)
|
107 |
+
resample_sr0 = gr.Slider(
|
108 |
+
minimum=0,
|
109 |
+
maximum=48000,
|
110 |
+
label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
|
111 |
+
value=0,
|
112 |
+
step=1,
|
113 |
+
interactive=True,
|
114 |
+
)
|
115 |
+
rms_mix_rate0 = gr.Slider(
|
116 |
+
minimum=0,
|
117 |
+
maximum=1,
|
118 |
+
label=i18n(
|
119 |
+
"输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"
|
120 |
+
),
|
121 |
+
value=1,
|
122 |
+
interactive=True,
|
123 |
+
)
|
124 |
+
protect0 = gr.Slider(
|
125 |
+
minimum=0,
|
126 |
+
maximum=0.5,
|
127 |
+
label=i18n(
|
128 |
+
"保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"
|
129 |
+
),
|
130 |
+
value=0.33,
|
131 |
+
step=0.01,
|
132 |
+
interactive=True,
|
133 |
+
)
|
134 |
+
f0_file = gr.File(
|
135 |
+
label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调")
|
136 |
+
)
|
137 |
+
but0 = gr.Button(i18n("转换"), variant="primary")
|
138 |
+
vc_output1 = gr.Textbox(label=i18n("输出信息"))
|
139 |
+
vc_output2 = gr.Audio(label=i18n("输出音频(右下角三个点,点了可以下载)"))
|
140 |
+
but0.click(
|
141 |
+
vc.vc_single,
|
142 |
+
[
|
143 |
+
spk_item,
|
144 |
+
vc_input3,
|
145 |
+
vc_transform0,
|
146 |
+
f0_file,
|
147 |
+
f0method0,
|
148 |
+
file_index1,
|
149 |
+
file_index2,
|
150 |
+
# file_big_npy1,
|
151 |
+
index_rate1,
|
152 |
+
filter_radius0,
|
153 |
+
resample_sr0,
|
154 |
+
rms_mix_rate0,
|
155 |
+
protect0,
|
156 |
+
],
|
157 |
+
[vc_output1, vc_output2],
|
158 |
+
)
|
159 |
+
|
160 |
+
|
161 |
+
app.launch()
|