File size: 14,089 Bytes
28af810 af8e0ab 28af810 af8e0ab 28af810 0489e92 28af810 0489e92 28af810 af8e0ab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | import os
import sys
now_dir = os.getcwd()
sys.path.append(now_dir)
from infer.modules.vc.modules import VC
from infer.modules.vc.utils import download_and_split_audio, combine_audio
from infer.lib.setting import change_audio_mode, show_description
from configs.config import Config
import numpy as np
import gradio as gr
import subprocess
import json
import shutil
import logging
import zipfile
import glob
import asyncio
import edge_tts
logging.getLogger("numba").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
config = Config()
vc = VC(config)
tts_voice_list = asyncio.new_event_loop().run_until_complete(edge_tts.list_voices())
tts_voices = [f"{v['ShortName']}-{v['Gender']}" for v in tts_voice_list]
os.makedirs("models", exist_ok=True)
os.makedirs(os.path.join("assets", "hubert"), exist_ok=True)
os.makedirs(os.path.join("assets", "rvmpe"), exist_ok=True)
os.makedirs(os.path.join("models", "weights"), exist_ok=True)
os.makedirs(os.path.join("models", "indexs"), exist_ok=True)
os.makedirs(os.path.join("models", "covers"), exist_ok=True)
models_path = "models"
weights_path = os.path.join("models", "weights")
indexs_path = os.path.join("models", "indexs")
covers_path = os.path.join("models", "covers")
force_support = None
if config.force_support is False:
if config.device == "mps" or config.device == "cpu":
force_support = False
else:
logger.info("\033[93mWARNING: Unsupported feature is enabled.\033[0m")
logger.info("\033[93mWARNING: It may not work properly.\033[0m")
force_support = True
audio_mode = []
f0method_mode = []
f0method_info = ""
if force_support is False:
audio_mode = ["Upload audio", "Input path", "TTS Audio"]
f0method_mode = ["pm", "rmvpe", "harvest"]
else:
audio_mode = ["Upload audio", "Input path", "Youtube", "TTS Audio"]
f0method_mode = ["pm", "rmvpe", "harvest", "crepe"]
json_files = []
for root, dirs, files in os.walk(models_path):
for file in files:
if file.endswith(".json"):
json_files.append(os.path.join(root, file))
if json_files:
with open(json_files[0], 'r') as file:
data = json.load(file)
modelList = data.get("list", [])
else:
data = {"list": [], "model_data": []}
modelList = []
names = []
indexs = []
for name in os.listdir(weights_path):
if name.endswith(".pth"):
names.append(name)
for name in os.listdir(indexs_path):
if name.endswith(".index"):
indexs.append(name)
def download_model(character):
os.makedirs("TEMP", exist_ok=True)
temp_path = "TEMP"
models = data.get("model_data", [])
for item in models:
if character == item[1]:
cover_filename = os.path.splitext(item[0])[0] + os.path.splitext(item[2])[1]
log1 = subprocess.run(['wget', '-P', temp_path, item[2]])
log2 = subprocess.run(['wget', '-O', os.path.join(covers_path, cover_filename), item[3]])
zip_files = glob.glob(os.path.join(temp_path, '*.zip'))
for zip_file in zip_files:
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
zip_ref.extractall(temp_path)
for root, dirs, files in os.walk(temp_path):
for file in files:
if file.endswith(".pth"):
weight_file = f"{character}.{file.split('.')[1]}"
os.rename(os.path.join(root, file), os.path.join(root, weight_file))
shutil.move(os.path.join(root, weight_file), os.path.join(weights_path, weight_file))
elif file.endswith(".index"):
if character not in file:
index_file = f"{file.split('.')[0]}_{character}.{file.split('.')[1]}"
os.rename(os.path.join(root, file), os.path.join(root, index_file))
shutil.move(os.path.join(root, index_file), os.path.join(indexs_path, index_file))
else:
shutil.move(os.path.join(root, file), os.path.join(indexs_path, file))
for dir in dirs:
for root_dirs, _, files_dirs in os.walk(os.path.join(root, dir)):
for file_dir in files_dirs:
if file_dir.endswith(".pth"):
weight_file = f"{character}.{file_dir.split('.')[1]}"
os.rename(os.path.join(root_dirs, file_dir), os.path.join(root_dirs, weight_file))
shutil.move(os.path.join(root_dirs, weight_file), os.path.join(weights_path, weight_file))
elif file_dir.endswith(".index"):
if character not in file_dir:
index_file = f"{file_dir.split('.')[0]}_{character}.{file_dir.split('.')[1]}"
os.rename(os.path.join(root_dirs, file_dir), os.path.join(root_dirs, index_file))
shutil.move(os.path.join(root_dirs, index_file), os.path.join(indexs_path, index_file))
else:
shutil.move(os.path.join(root_dirs, file_dir), os.path.join(indexs_path, file_dir))
shutil.rmtree(temp_path)
def change_choices():
names = []
indexs = []
for name in os.listdir(weights_path):
if name.endswith(".pth"):
names.append(name)
for name in os.listdir(indexs_path):
if name.endswith(".index"):
indexs.append(name)
return { "choices": sorted(names), "__type__": "update"}, {
"choices": sorted(indexs),
"__type__": "update",
}
def clean():
return {"value": "", "__type__": "update"}
with gr.Blocks(title="RVC WebUI", theme=gr.themes.Base()) as app:
gr.Markdown("<center> # RVC WebUI")
gr.Markdown("v1.0.0Beta")
with gr.Tabs():
with gr.TabItem("Inference"):
with gr.Row():
modelSelect = gr.Dropdown(label="Model", choices=sorted(modelList))
downloadModel = gr.Button("Download Model", variant="primary")
downloadModel.click(fn=download_model, inputs=[modelSelect], outputs=[])
with gr.Row():
sid0 = gr.Dropdown(label="Selected Model", choices=sorted(names))
file_index = gr.Dropdown(
label="Index file dropdown",
choices=sorted(indexs),
interactive=True,
)
spk_item = gr.Slider(
minimum=0,
maximum=2333,
step=1,
label="Speaker ID",
value=0,
visible=True,
interactive=True,
)
with gr.Column():
refresh_button = gr.Button("Refresh model", variant="primary")
clean_button = gr.Button("Clean memory", variant="primary")
clean_button.click(fn=clean, inputs=[], outputs=[sid0], api_name="infer_clean")
with gr.TabItem("Inference Setting"):
with gr.Row():
with gr.Column():
vc_audio_mode = gr.Dropdown(label="Input voice", choices=audio_mode, value="Upload audio", visible=True, interactive=True)
vc_upload = gr.Audio(label="Upload audio file", sources=["upload", "microphone"], visible=True, interactive=True)
vc_audio_input = gr.Textbox(label="Audio Input Path", placeholder="C:\\Users\\Desktop\\audio_example.wav", visible=False, interactive=True)
vc_link = gr.Textbox(label="Youtube URL", visible=False, placeholder="https://www.youtube.com/watch?v=...", interactive=True)
vc_split_model = gr.Dropdown(label="Splitter Model", choices=["hdemucs_mmi", "htdemucs", "htdemucs_ft", "mdx", "mdx_extra", "mdx_extra_q"], allow_custom_value=False, visible=False, value="htdemucs", interactive=True)
vc_download_button = gr.Button("Download Audio", variant="primary", visible=False)
vc_vocal_preview = gr.Audio(label="Vocal Preview", visible=False)
vc_tts_text = gr.Textbox(label="TTS text", placeholder="Hello world", visible=False, interactive=True)
vc_tts_voice = gr.Dropdown(label="Edge-tts speaker", choices=tts_voices, visible=False, allow_custom_value=False, value="en-US-AnaNeural-Female", interactive=True)
vc_inst_input = gr.Textbox(label="Inst Input", value="", visible=False)
with gr.Column():
f0method0 = gr.Radio(
label="Pitch extraction algorithm",
choices=f0method_mode
if config.dml == False
else ["pm", "harvest", "rmvpe"],
value="pm",
interactive=True,
)
vc_transform0 = gr.Slider(
label="Transpose",
minimum=-256,
maximum=256,
step=0.01,
value=0,
interactive=True,
)
index_rate = gr.Slider(
minimum=0,
maximum=1,
label="Retrieval feature ratio",
value=0.6,
interactive=True,
)
resample_sr0 = gr.Slider(
minimum=0,
maximum=48000,
label="Resample the output audio",
value=0,
step=1,
interactive=True,
)
rms_mix_rate0 = gr.Slider(
minimum=0,
maximum=1,
label="Volume Envelope",
value=0,
interactive=True,
)
protect0 = gr.Slider(
minimum=0,
maximum=0.5,
label="Voice Protection",
value=0.5,
step=0.01,
interactive=True,
)
filter_radius0 = gr.Slider(
minimum=0,
maximum=7,
label="Apply Median Filtering",
value=2,
step=1,
interactive=True,
)
refresh_button.click(
fn=change_choices,
inputs=[],
outputs=[sid0, file_index],
api_name="infer_refresh",
)
with gr.Column():
but0 = gr.Button("Run", variant="primary")
vc_output = gr.Audio(label="Output Audio")
vc_combined = gr.Button("Combine", variant="primary")
vc_combined_output = gr.Audio(label="Combined Audio")
with gr.TabItem("Log"):
gr.Markdown("## Log")
vc_log = gr.Textbox(label="Output Log", max_lines=40, lines=40)
with gr.TabItem("Settings"):
gr.Markdown("## Setting")
description_mode = gr.Checkbox(label="Show description", value=False)
description_mode.change(
fn=show_description,
inputs=description_mode,
outputs=[
vc_audio_input,
vc_link,
vc_split_model,
vc_tts_text,
vc_tts_voice,
f0method0,
vc_transform0,
index_rate,
resample_sr0,
rms_mix_rate0,
protect0,
filter_radius0
]
)
but0.click(
vc.vc_single,
[
spk_item,
vc_audio_mode,
vc_audio_input,
vc_upload,
vc_tts_text,
vc_tts_voice,
vc_transform0,
f0method0,
file_index,
index_rate,
filter_radius0,
resample_sr0,
rms_mix_rate0,
protect0
],
[vc_log, vc_output, vc_inst_input],
api_name="infer_convert",
)
sid0.change(
fn=vc.get_vc,
inputs=[sid0, protect0],
outputs=[spk_item, protect0, file_index],
api_name="infer_change_voice",
)
vc_download_button.click(
fn=download_and_split_audio,
inputs=[vc_link, vc_split_model],
outputs=[vc_vocal_preview, vc_audio_input, vc_log]
)
vc_combined.click(
fn=combine_audio,
inputs=[vc_split_model, vc_inst_input],
outputs=[vc_combined_output, vc_log]
)
vc_audio_mode.change(
fn=change_audio_mode,
inputs=[vc_audio_mode],
outputs=[
vc_upload,
vc_audio_input,
vc_link,
vc_split_model,
vc_download_button,
vc_vocal_preview,
vc_tts_text,
vc_tts_voice,
vc_combined,
vc_combined_output,
]
)
if config.iscolab:
app.launch(share=True)
else:
app.launch(
server_name="0.0.0.0",
inbrowser=not config.noautoopen,
server_port=config.listen_port,
quiet=True,
) |