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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess, torch, os, traceback, sys, warnings, shutil
|
| 2 |
+
os.environ["no_proxy"] = "localhost, 127.0.0.1, ::1"
|
| 3 |
+
import threading
|
| 4 |
+
from time import sleep
|
| 5 |
+
from subprocess import Popen
|
| 6 |
+
import faiss
|
| 7 |
+
import json, datetime, requests
|
| 8 |
+
from gtts import gTTS
|
| 9 |
+
now_dir = os.getcwd()
|
| 10 |
+
sys.path.append(now_dir)
|
| 11 |
+
tmp = os.path.join(now_dir, "TEMP")
|
| 12 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 13 |
+
os.makedirs(os.path.join(now_dir, "weights"), exist_ok=True)
|
| 14 |
+
os.environ["TEMP"] = tmp
|
| 15 |
+
warnings.filterwarnings("ignore")
|
| 16 |
+
torch.manual_seed(114514)
|
| 17 |
+
from i18n import I18nAuto
|
| 18 |
+
import edge_tts, asyncio
|
| 19 |
+
from ilariatts import tts_order_voice
|
| 20 |
+
from lib.infer_pack.models import (
|
| 21 |
+
SynthesizerTrnMs256NSFsid,
|
| 22 |
+
SynthesizerTrnMs256NSFsid_nono,
|
| 23 |
+
SynthesizerTrnMs768NSFsid,
|
| 24 |
+
SynthesizerTrnMs768NSFsid_nono,
|
| 25 |
+
)
|
| 26 |
+
import soundfile as sf
|
| 27 |
+
from fairseq import checkpoint_utils
|
| 28 |
+
import gradio as gr
|
| 29 |
+
import logging
|
| 30 |
+
from pipeline import VC
|
| 31 |
+
from config import Config
|
| 32 |
+
from utils import *
|
| 33 |
+
config = Config()
|
| 34 |
+
logging.getLogger("numba").setLevel(logging.WARNING)
|
| 35 |
+
|
| 36 |
+
hubert_model = None
|
| 37 |
+
language_dict = tts_order_voice
|
| 38 |
+
ilariavoices = language_dict.keys()
|
| 39 |
+
|
| 40 |
+
import signal
|
| 41 |
+
|
| 42 |
+
import math
|
| 43 |
+
|
| 44 |
+
from utils import load_audio, CSVutil
|
| 45 |
+
|
| 46 |
+
global DoFormant, Quefrency, Timbre
|
| 47 |
+
|
| 48 |
+
if not os.path.isdir('csvdb/'):
|
| 49 |
+
os.makedirs('csvdb')
|
| 50 |
+
frmnt, stp = open("csvdb/formanting.csv", 'w'), open("csvdb/stop.csv", 'w')
|
| 51 |
+
frmnt.close()
|
| 52 |
+
stp.close()
|
| 53 |
+
|
| 54 |
+
try:
|
| 55 |
+
DoFormant, Quefrency, Timbre = CSVutil('csvdb/formanting.csv', 'r', 'formanting')
|
| 56 |
+
DoFormant = (
|
| 57 |
+
lambda DoFormant: True if DoFormant.lower() == 'true' else (False if DoFormant.lower() == 'false' else DoFormant)
|
| 58 |
+
)(DoFormant)
|
| 59 |
+
except (ValueError, TypeError, IndexError):
|
| 60 |
+
DoFormant, Quefrency, Timbre = False, 1.0, 1.0
|
| 61 |
+
CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, Quefrency, Timbre)
|
| 62 |
+
|
| 63 |
+
def download_models():
|
| 64 |
+
# Download hubert base model if not present
|
| 65 |
+
if not os.path.isfile('./hubert_base.pt'):
|
| 66 |
+
response = requests.get('https://huggingface.co/buckets/R-Kentaren/rvcmodels-bucket/resolve/main/hubert_base.pt?download=true')
|
| 67 |
+
|
| 68 |
+
if response.status_code == 200:
|
| 69 |
+
with open('./hubert_base.pt', 'wb') as f:
|
| 70 |
+
f.write(response.content)
|
| 71 |
+
print("Downloaded hubert base model file successfully. File saved to ./hubert_base.pt.")
|
| 72 |
+
else:
|
| 73 |
+
raise Exception("Failed to download hubert base model file. Status code: " + str(response.status_code) + ".")
|
| 74 |
+
|
| 75 |
+
# Download rmvpe model if not present
|
| 76 |
+
if not os.path.isfile('./rmvpe.pt'):
|
| 77 |
+
response = requests.get('https://huggingface.co/buckets/R-Kentaren/rvcmodels-bucket/resolve/main/rmvpe.pt?download=true')
|
| 78 |
+
|
| 79 |
+
if response.status_code == 200:
|
| 80 |
+
with open('./rmvpe.pt', 'wb') as f:
|
| 81 |
+
f.write(response.content)
|
| 82 |
+
print("Downloaded rmvpe model file successfully. File saved to ./rmvpe.pt.")
|
| 83 |
+
else:
|
| 84 |
+
raise Exception("Failed to download rmvpe model file. Status code: " + str(response.status_code) + ".")
|
| 85 |
+
|
| 86 |
+
download_models()
|
| 87 |
+
|
| 88 |
+
print("\n-------------------------------\nRVC v2 Easy GUI\n-------------------------------\n")
|
| 89 |
+
|
| 90 |
+
def formant_apply(qfrency, tmbre):
|
| 91 |
+
Quefrency = qfrency
|
| 92 |
+
Timbre = tmbre
|
| 93 |
+
DoFormant = True
|
| 94 |
+
CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
|
| 95 |
+
|
| 96 |
+
return ({"value": Quefrency, "__type__": "update"}, {"value": Timbre, "__type__": "update"})
|
| 97 |
+
|
| 98 |
+
def get_fshift_presets():
|
| 99 |
+
fshift_presets_list = []
|
| 100 |
+
for dirpath, _, filenames in os.walk("./formantshiftcfg/"):
|
| 101 |
+
for filename in filenames:
|
| 102 |
+
if filename.endswith(".txt"):
|
| 103 |
+
fshift_presets_list.append(os.path.join(dirpath,filename).replace('\\','/'))
|
| 104 |
+
|
| 105 |
+
if len(fshift_presets_list) > 0:
|
| 106 |
+
return fshift_presets_list
|
| 107 |
+
else:
|
| 108 |
+
return ''
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def formant_enabled(cbox, qfrency, tmbre, frmntapply, formantpreset, formant_refresh_button):
|
| 113 |
+
|
| 114 |
+
if (cbox):
|
| 115 |
+
|
| 116 |
+
DoFormant = True
|
| 117 |
+
CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
|
| 118 |
+
|
| 119 |
+
return (
|
| 120 |
+
{"value": True, "__type__": "update"},
|
| 121 |
+
{"visible": True, "__type__": "update"},
|
| 122 |
+
{"visible": True, "__type__": "update"},
|
| 123 |
+
{"visible": True, "__type__": "update"},
|
| 124 |
+
{"visible": True, "__type__": "update"},
|
| 125 |
+
{"visible": True, "__type__": "update"},
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
else:
|
| 130 |
+
|
| 131 |
+
DoFormant = False
|
| 132 |
+
CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
|
| 133 |
+
|
| 134 |
+
return (
|
| 135 |
+
{"value": False, "__type__": "update"},
|
| 136 |
+
{"visible": False, "__type__": "update"},
|
| 137 |
+
{"visible": False, "__type__": "update"},
|
| 138 |
+
{"visible": False, "__type__": "update"},
|
| 139 |
+
{"visible": False, "__type__": "update"},
|
| 140 |
+
{"visible": False, "__type__": "update"},
|
| 141 |
+
{"visible": False, "__type__": "update"},
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def preset_apply(preset, qfer, tmbr):
|
| 147 |
+
if str(preset) != '':
|
| 148 |
+
with open(str(preset), 'r') as p:
|
| 149 |
+
content = p.readlines()
|
| 150 |
+
qfer, tmbr = content[0].split('\n')[0], content[1]
|
| 151 |
+
|
| 152 |
+
formant_apply(qfer, tmbr)
|
| 153 |
+
else:
|
| 154 |
+
pass
|
| 155 |
+
return ({"value": qfer, "__type__": "update"}, {"value": tmbr, "__type__": "update"})
|
| 156 |
+
|
| 157 |
+
def update_fshift_presets(preset, qfrency, tmbre):
|
| 158 |
+
|
| 159 |
+
qfrency, tmbre = preset_apply(preset, qfrency, tmbre)
|
| 160 |
+
|
| 161 |
+
if (str(preset) != ''):
|
| 162 |
+
with open(str(preset), 'r') as p:
|
| 163 |
+
content = p.readlines()
|
| 164 |
+
qfrency, tmbre = content[0].split('\n')[0], content[1]
|
| 165 |
+
|
| 166 |
+
formant_apply(qfrency, tmbre)
|
| 167 |
+
else:
|
| 168 |
+
pass
|
| 169 |
+
return (
|
| 170 |
+
{"choices": get_fshift_presets(), "__type__": "update"},
|
| 171 |
+
{"value": qfrency, "__type__": "update"},
|
| 172 |
+
{"value": tmbre, "__type__": "update"},
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
i18n = I18nAuto(language="pt_BR")
|
| 176 |
+
ngpu = torch.cuda.device_count()
|
| 177 |
+
gpu_infos = []
|
| 178 |
+
mem = []
|
| 179 |
+
if (not torch.cuda.is_available()) or ngpu == 0:
|
| 180 |
+
if_gpu_ok = False
|
| 181 |
+
else:
|
| 182 |
+
if_gpu_ok = False
|
| 183 |
+
for i in range(ngpu):
|
| 184 |
+
gpu_name = torch.cuda.get_device_name(i)
|
| 185 |
+
if (
|
| 186 |
+
"10" in gpu_name
|
| 187 |
+
or "16" in gpu_name
|
| 188 |
+
or "20" in gpu_name
|
| 189 |
+
or "30" in gpu_name
|
| 190 |
+
or "40" in gpu_name
|
| 191 |
+
or "A2" in gpu_name.upper()
|
| 192 |
+
or "A3" in gpu_name.upper()
|
| 193 |
+
or "A4" in gpu_name.upper()
|
| 194 |
+
or "P4" in gpu_name.upper()
|
| 195 |
+
or "A50" in gpu_name.upper()
|
| 196 |
+
or "A60" in gpu_name.upper()
|
| 197 |
+
or "70" in gpu_name
|
| 198 |
+
or "80" in gpu_name
|
| 199 |
+
or "90" in gpu_name
|
| 200 |
+
or "M4" in gpu_name.upper()
|
| 201 |
+
or "T4" in gpu_name.upper()
|
| 202 |
+
or "TITAN" in gpu_name.upper()
|
| 203 |
+
):
|
| 204 |
+
if_gpu_ok = True
|
| 205 |
+
gpu_infos.append("%s\t%s" % (i, gpu_name))
|
| 206 |
+
mem.append(
|
| 207 |
+
int(
|
| 208 |
+
torch.cuda.get_device_properties(i).total_memory
|
| 209 |
+
/ 1024
|
| 210 |
+
/ 1024
|
| 211 |
+
/ 1024
|
| 212 |
+
+ 0.4
|
| 213 |
+
)
|
| 214 |
+
)
|
| 215 |
+
if if_gpu_ok == True and len(gpu_infos) > 0:
|
| 216 |
+
gpu_info = "\n".join(gpu_infos)
|
| 217 |
+
default_batch_size = min(mem) // 2
|
| 218 |
+
else:
|
| 219 |
+
gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
|
| 220 |
+
default_batch_size = 1
|
| 221 |
+
gpus = "-".join([i[0] for i in gpu_infos])
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def load_hubert():
|
| 225 |
+
global hubert_model
|
| 226 |
+
models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
|
| 227 |
+
["hubert_base.pt"],
|
| 228 |
+
suffix="",
|
| 229 |
+
)
|
| 230 |
+
hubert_model = models[0]
|
| 231 |
+
hubert_model = hubert_model.to(config.device)
|
| 232 |
+
if config.is_half:
|
| 233 |
+
hubert_model = hubert_model.half()
|
| 234 |
+
else:
|
| 235 |
+
hubert_model = hubert_model.float()
|
| 236 |
+
hubert_model.eval()
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
weight_root = "weights"
|
| 240 |
+
index_root = "logs"
|
| 241 |
+
names = []
|
| 242 |
+
for name in os.listdir(weight_root):
|
| 243 |
+
if name.endswith(".pth"):
|
| 244 |
+
names.append(name)
|
| 245 |
+
index_paths = []
|
| 246 |
+
for root, dirs, files in os.walk(index_root, topdown=False):
|
| 247 |
+
for name in files:
|
| 248 |
+
if name.endswith(".index") and "trained" not in name:
|
| 249 |
+
index_paths.append("%s/%s" % (root, name))
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
@spaces.GPU
|
| 253 |
+
def vc_single(
|
| 254 |
+
sid,
|
| 255 |
+
input_audio_path,
|
| 256 |
+
f0_up_key,
|
| 257 |
+
f0_file,
|
| 258 |
+
f0_method,
|
| 259 |
+
file_index,
|
| 260 |
+
index_rate,
|
| 261 |
+
filter_radius,
|
| 262 |
+
resample_sr,
|
| 263 |
+
rms_mix_rate,
|
| 264 |
+
protect,
|
| 265 |
+
crepe_hop_length,
|
| 266 |
+
):
|
| 267 |
+
global tgt_sr, net_g, vc, hubert_model, version
|
| 268 |
+
if input_audio_path is None:
|
| 269 |
+
return "You need to upload an audio", None
|
| 270 |
+
f0_up_key = int(f0_up_key)
|
| 271 |
+
try:
|
| 272 |
+
audio = load_audio(input_audio_path, 16000, DoFormant, Quefrency, Timbre)
|
| 273 |
+
audio_max = abs(audio).max() / 0.95
|
| 274 |
+
if audio_max > 1:
|
| 275 |
+
audio /= audio_max
|
| 276 |
+
times = [0, 0, 0]
|
| 277 |
+
if hubert_model == None:
|
| 278 |
+
load_hubert()
|
| 279 |
+
if_f0 = cpt.get("f0", 1)
|
| 280 |
+
file_index = (
|
| 281 |
+
(
|
| 282 |
+
file_index.strip(" ")
|
| 283 |
+
.strip('"')
|
| 284 |
+
.strip("\n")
|
| 285 |
+
.strip('"')
|
| 286 |
+
.strip(" ")
|
| 287 |
+
.replace("trained", "added")
|
| 288 |
+
)
|
| 289 |
+
)
|
| 290 |
+
audio_opt = vc.pipeline(
|
| 291 |
+
hubert_model,
|
| 292 |
+
net_g,
|
| 293 |
+
sid,
|
| 294 |
+
audio,
|
| 295 |
+
input_audio_path,
|
| 296 |
+
times,
|
| 297 |
+
f0_up_key,
|
| 298 |
+
f0_method,
|
| 299 |
+
file_index,
|
| 300 |
+
index_rate,
|
| 301 |
+
if_f0,
|
| 302 |
+
filter_radius,
|
| 303 |
+
tgt_sr,
|
| 304 |
+
resample_sr,
|
| 305 |
+
rms_mix_rate,
|
| 306 |
+
version,
|
| 307 |
+
protect,
|
| 308 |
+
crepe_hop_length,
|
| 309 |
+
f0_file=f0_file,
|
| 310 |
+
)
|
| 311 |
+
if resample_sr >= 16000 and tgt_sr != resample_sr:
|
| 312 |
+
tgt_sr = resample_sr
|
| 313 |
+
index_info = (
|
| 314 |
+
"Using index:%s." % file_index
|
| 315 |
+
if os.path.exists(file_index)
|
| 316 |
+
else "Index not used."
|
| 317 |
+
)
|
| 318 |
+
return "Success.\n %s\nTime:\n npy:%ss, f0:%ss, infer:%ss" % (
|
| 319 |
+
index_info,
|
| 320 |
+
times[0],
|
| 321 |
+
times[1],
|
| 322 |
+
times[2],
|
| 323 |
+
), (tgt_sr, audio_opt)
|
| 324 |
+
except:
|
| 325 |
+
info = traceback.format_exc()
|
| 326 |
+
print(info)
|
| 327 |
+
return info, (None, None)
|
| 328 |
+
|
| 329 |
+
def get_vc(sid):
|
| 330 |
+
global n_spk, tgt_sr, net_g, vc, cpt, version
|
| 331 |
+
if sid == "" or sid == []:
|
| 332 |
+
global hubert_model
|
| 333 |
+
if hubert_model != None:
|
| 334 |
+
print("clean_empty_cache")
|
| 335 |
+
del net_g, n_spk, vc, hubert_model, tgt_sr
|
| 336 |
+
hubert_model = net_g = n_spk = vc = hubert_model = tgt_sr = None
|
| 337 |
+
if torch.cuda.is_available():
|
| 338 |
+
torch.cuda.empty_cache()
|
| 339 |
+
if_f0 = cpt.get("f0", 1)
|
| 340 |
+
version = cpt.get("version", "v1")
|
| 341 |
+
if version == "v1":
|
| 342 |
+
if if_f0 == 1:
|
| 343 |
+
net_g = SynthesizerTrnMs256NSFsid(
|
| 344 |
+
*cpt["config"], is_half=config.is_half
|
| 345 |
+
)
|
| 346 |
+
else:
|
| 347 |
+
net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
|
| 348 |
+
elif version == "v2":
|
| 349 |
+
if if_f0 == 1:
|
| 350 |
+
net_g = SynthesizerTrnMs768NSFsid(
|
| 351 |
+
*cpt["config"], is_half=config.is_half
|
| 352 |
+
)
|
| 353 |
+
else:
|
| 354 |
+
net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
|
| 355 |
+
del net_g, cpt
|
| 356 |
+
if torch.cuda.is_available():
|
| 357 |
+
torch.cuda.empty_cache()
|
| 358 |
+
cpt = None
|
| 359 |
+
return {"visible": False, "__type__": "update"}
|
| 360 |
+
person = "%s/%s" % (weight_root, sid)
|
| 361 |
+
print("loading %s" % person)
|
| 362 |
+
cpt = torch.load(person, map_location="cpu")
|
| 363 |
+
tgt_sr = cpt["config"][-1]
|
| 364 |
+
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0]
|
| 365 |
+
if_f0 = cpt.get("f0", 1)
|
| 366 |
+
version = cpt.get("version", "v1")
|
| 367 |
+
if version == "v1":
|
| 368 |
+
if if_f0 == 1:
|
| 369 |
+
net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
|
| 370 |
+
else:
|
| 371 |
+
net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
|
| 372 |
+
elif version == "v2":
|
| 373 |
+
if if_f0 == 1:
|
| 374 |
+
net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
|
| 375 |
+
else:
|
| 376 |
+
net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
|
| 377 |
+
del net_g.enc_q
|
| 378 |
+
print(net_g.load_state_dict(cpt["weight"], strict=False))
|
| 379 |
+
net_g.eval().to(config.device)
|
| 380 |
+
if config.is_half:
|
| 381 |
+
net_g = net_g.half()
|
| 382 |
+
else:
|
| 383 |
+
net_g = net_g.float()
|
| 384 |
+
vc = VC(tgt_sr, config)
|
| 385 |
+
n_spk = cpt["config"][-3]
|
| 386 |
+
return {"visible": False, "maximum": n_spk, "__type__": "update"}
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
def change_choices():
|
| 390 |
+
names = []
|
| 391 |
+
for name in os.listdir(weight_root):
|
| 392 |
+
if name.endswith(".pth"):
|
| 393 |
+
names.append(name)
|
| 394 |
+
index_paths = []
|
| 395 |
+
for root, dirs, files in os.walk(index_root, topdown=False):
|
| 396 |
+
for name in files:
|
| 397 |
+
if name.endswith(".index") and "trained" not in name:
|
| 398 |
+
index_paths.append("%s/%s" % (root, name))
|
| 399 |
+
return {"choices": sorted(names), "__type__": "update"}, {
|
| 400 |
+
"choices": sorted(index_paths),
|
| 401 |
+
"__type__": "update",
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def clean():
|
| 406 |
+
return {"value": "", "__type__": "update"}
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
sr_dict = {
|
| 410 |
+
"32k": 32000,
|
| 411 |
+
"40k": 40000,
|
| 412 |
+
"48k": 48000,
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
def whethercrepeornah(radio):
|
| 417 |
+
mango = True if radio == 'mangio-crepe' or radio == 'mangio-crepe-tiny' else False
|
| 418 |
+
return ({"visible": mango, "__type__": "update"})
|
| 419 |
+
|
| 420 |
+
from lib.infer_pack.models_onnx import SynthesizerTrnMsNSFsidM
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
def export_onnx(ModelPath, ExportedPath, MoeVS=True):
|
| 424 |
+
cpt = torch.load(ModelPath, map_location="cpu")
|
| 425 |
+
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0]
|
| 426 |
+
hidden_channels = 256 if cpt.get("version","v1")=="v1"else 768
|
| 427 |
+
|
| 428 |
+
test_phone = torch.rand(1, 200, hidden_channels)
|
| 429 |
+
test_phone_lengths = torch.tensor([200]).long()
|
| 430 |
+
test_pitch = torch.randint(size=(1, 200), low=5, high=255)
|
| 431 |
+
test_pitchf = torch.rand(1, 200)
|
| 432 |
+
test_ds = torch.LongTensor([0])
|
| 433 |
+
test_rnd = torch.rand(1, 192, 200)
|
| 434 |
+
|
| 435 |
+
device = "cpu"
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
net_g = SynthesizerTrnMsNSFsidM(
|
| 439 |
+
*cpt["config"], is_half=False,version=cpt.get("version","v1")
|
| 440 |
+
)
|
| 441 |
+
net_g.load_state_dict(cpt["weight"], strict=False)
|
| 442 |
+
input_names = ["phone", "phone_lengths", "pitch", "pitchf", "ds", "rnd"]
|
| 443 |
+
output_names = [
|
| 444 |
+
"audio",
|
| 445 |
+
]
|
| 446 |
+
torch.onnx.export(
|
| 447 |
+
net_g,
|
| 448 |
+
(
|
| 449 |
+
test_phone.to(device),
|
| 450 |
+
test_phone_lengths.to(device),
|
| 451 |
+
test_pitch.to(device),
|
| 452 |
+
test_pitchf.to(device),
|
| 453 |
+
test_ds.to(device),
|
| 454 |
+
test_rnd.to(device),
|
| 455 |
+
),
|
| 456 |
+
ExportedPath,
|
| 457 |
+
dynamic_axes={
|
| 458 |
+
"phone": [1],
|
| 459 |
+
"pitch": [1],
|
| 460 |
+
"pitchf": [1],
|
| 461 |
+
"rnd": [2],
|
| 462 |
+
},
|
| 463 |
+
do_constant_folding=False,
|
| 464 |
+
opset_version=16,
|
| 465 |
+
verbose=False,
|
| 466 |
+
input_names=input_names,
|
| 467 |
+
output_names=output_names,
|
| 468 |
+
)
|
| 469 |
+
return "Finished"
|
| 470 |
+
|
| 471 |
+
def change_choices2():
|
| 472 |
+
audio_files=[]
|
| 473 |
+
for filename in os.listdir("./audios"):
|
| 474 |
+
if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
|
| 475 |
+
audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
|
| 476 |
+
return {"choices": sorted(audio_files), "__type__": "update"}, {"__type__": "update"}
|
| 477 |
+
|
| 478 |
+
audio_files=[]
|
| 479 |
+
for filename in os.listdir("./audios"):
|
| 480 |
+
if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
|
| 481 |
+
audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
|
| 482 |
+
|
| 483 |
+
def get_index():
|
| 484 |
+
if check_for_name() != '':
|
| 485 |
+
chosen_model=sorted(names)[0].split(".")[0]
|
| 486 |
+
logs_path="./logs/"+chosen_model
|
| 487 |
+
if os.path.exists(logs_path):
|
| 488 |
+
for file in os.listdir(logs_path):
|
| 489 |
+
if file.endswith(".index"):
|
| 490 |
+
return os.path.join(logs_path, file)
|
| 491 |
+
return ''
|
| 492 |
+
else:
|
| 493 |
+
return ''
|
| 494 |
+
|
| 495 |
+
def get_indexes():
|
| 496 |
+
indexes_list=[]
|
| 497 |
+
for dirpath, dirnames, filenames in os.walk("./logs/"):
|
| 498 |
+
for filename in filenames:
|
| 499 |
+
if filename.endswith(".index"):
|
| 500 |
+
indexes_list.append(os.path.join(dirpath,filename))
|
| 501 |
+
if len(indexes_list) > 0:
|
| 502 |
+
return indexes_list
|
| 503 |
+
else:
|
| 504 |
+
return ''
|
| 505 |
+
|
| 506 |
+
def get_name():
|
| 507 |
+
if len(audio_files) > 0:
|
| 508 |
+
return sorted(audio_files)[0]
|
| 509 |
+
else:
|
| 510 |
+
return ''
|
| 511 |
+
|
| 512 |
+
def save_to_wav(record_button):
|
| 513 |
+
if record_button is None:
|
| 514 |
+
pass
|
| 515 |
+
else:
|
| 516 |
+
path_to_file=record_button
|
| 517 |
+
new_name = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+'.wav'
|
| 518 |
+
new_path='./audios/'+new_name
|
| 519 |
+
shutil.move(path_to_file,new_path)
|
| 520 |
+
return new_path
|
| 521 |
+
|
| 522 |
+
def save_to_wav2(dropbox):
|
| 523 |
+
file_path=dropbox.name
|
| 524 |
+
shutil.move(file_path,'./audios')
|
| 525 |
+
return os.path.join('./audios',os.path.basename(file_path))
|
| 526 |
+
|
| 527 |
+
def match_index(sid0):
|
| 528 |
+
folder=sid0.split(".")[0]
|
| 529 |
+
parent_dir="./logs/"+folder
|
| 530 |
+
if os.path.exists(parent_dir):
|
| 531 |
+
for filename in os.listdir(parent_dir):
|
| 532 |
+
if filename.endswith(".index"):
|
| 533 |
+
index_path=os.path.join(parent_dir,filename)
|
| 534 |
+
return index_path
|
| 535 |
+
else:
|
| 536 |
+
return ''
|
| 537 |
+
|
| 538 |
+
def check_for_name():
|
| 539 |
+
if len(names) > 0:
|
| 540 |
+
return sorted(names)[0]
|
| 541 |
+
else:
|
| 542 |
+
return ''
|
| 543 |
+
|
| 544 |
+
|
| 545 |
+
def ilariaTTS(text, ttsvoice):
|
| 546 |
+
vo=language_dict[ttsvoice]
|
| 547 |
+
asyncio.run(edge_tts.Communicate(text, vo).save("./temp_ilaria.mp3"))
|
| 548 |
+
aud_path = save_to_wav('./temp_ilaria.mp3')
|
| 549 |
+
return aud_path, aud_path
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
def download_from_url(url, model):
|
| 553 |
+
if not url:
|
| 554 |
+
return "The URL cannot be empty."
|
| 555 |
+
if not model:
|
| 556 |
+
return "You need to name your model. For example: My model"
|
| 557 |
+
|
| 558 |
+
url = url.strip()
|
| 559 |
+
zip_dirs = ["zips", "unzips"]
|
| 560 |
+
for directory in zip_dirs:
|
| 561 |
+
if os.path.exists(directory):
|
| 562 |
+
shutil.rmtree(directory)
|
| 563 |
+
os.makedirs("zips", exist_ok=True)
|
| 564 |
+
os.makedirs("unzips", exist_ok=True)
|
| 565 |
+
zipfile = model + '.zip'
|
| 566 |
+
zipfile_path = './zips/' + zipfile
|
| 567 |
+
try:
|
| 568 |
+
if "drive.google.com" in url:
|
| 569 |
+
subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
|
| 570 |
+
else:
|
| 571 |
+
subprocess.run(["wget", url, "-O", zipfile_path])
|
| 572 |
+
for filename in os.listdir("./zips"):
|
| 573 |
+
if filename.endswith(".zip"):
|
| 574 |
+
zipfile_path = os.path.join("./zips/", filename)
|
| 575 |
+
shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
|
| 576 |
+
else:
|
| 577 |
+
return "No zipfile found."
|
| 578 |
+
for root, dirs, files in os.walk('./unzips'):
|
| 579 |
+
for file in files:
|
| 580 |
+
file_path = os.path.join(root, file)
|
| 581 |
+
if file.endswith(".index"):
|
| 582 |
+
os.mkdir(f'./logs/{model}')
|
| 583 |
+
shutil.copy2(file_path, f'./logs/{model}')
|
| 584 |
+
elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
|
| 585 |
+
shutil.copy(file_path, f'./weights/{model}.pth')
|
| 586 |
+
shutil.rmtree("zips")
|
| 587 |
+
shutil.rmtree("unzips")
|
| 588 |
+
return "Model downloaded, you can return to the inference page!"
|
| 589 |
+
except:
|
| 590 |
+
return "ERROR - download failed. Check if the link is valid."
|
| 591 |
+
|
| 592 |
+
with gr.Blocks(theme=gr.themes.Default(primary_hue="red", secondary_hue="red"), title="RVC - AsukaDev", css=css) as app:
|
| 593 |
+
gr.Markdown(badges)
|
| 594 |
+
gr.Markdown(description)
|
| 595 |
+
|
| 596 |
+
gr.HTML("<h1> Easy GUI</h1>")
|
| 597 |
+
with gr.Tabs():
|
| 598 |
+
with gr.TabItem("Inference"):
|
| 599 |
+
with gr.Row():
|
| 600 |
+
sid0 = gr.Dropdown(label="1. Choose your model", choices=sorted(names), value=check_for_name())
|
| 601 |
+
refresh_button = gr.Button("To update", variant="primary")
|
| 602 |
+
if check_for_name() != '':
|
| 603 |
+
get_vc(sorted(names)[0])
|
| 604 |
+
vc_transform0 = gr.Number(label="Change the tone here. If the voice is of the same sex, it is not necessary to change (12 if it is Male to Female, -12 if it is the other way around.", value=0)
|
| 605 |
+
spk_item = gr.Slider(
|
| 606 |
+
minimum=0,
|
| 607 |
+
maximum=2333,
|
| 608 |
+
step=1,
|
| 609 |
+
label=i18n("请选择说话人id"),
|
| 610 |
+
value=0,
|
| 611 |
+
visible=False,
|
| 612 |
+
interactive=True,
|
| 613 |
+
)
|
| 614 |
+
sid0.change(
|
| 615 |
+
fn=get_vc,
|
| 616 |
+
inputs=[sid0],
|
| 617 |
+
outputs=[spk_item],
|
| 618 |
+
)
|
| 619 |
+
but0 = gr.Button("Converter", variant="primary")
|
| 620 |
+
with gr.Row():
|
| 621 |
+
with gr.Column():
|
| 622 |
+
with gr.Row():
|
| 623 |
+
dropbox = gr.File(label="Drag your audio file and click update.")
|
| 624 |
+
with gr.Row():
|
| 625 |
+
record_button=gr.Audio(sources="microphone", label="Or you can use your microphone!", type="filepath")
|
| 626 |
+
with gr.Row():
|
| 627 |
+
input_audio0 = gr.Dropdown(
|
| 628 |
+
label="2.Choose the audio file",
|
| 629 |
+
value="./audios/Poema-do-Cume-Arnold",
|
| 630 |
+
choices=audio_files
|
| 631 |
+
)
|
| 632 |
+
dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[input_audio0])
|
| 633 |
+
dropbox.upload(fn=change_choices2, inputs=[], outputs=[input_audio0])
|
| 634 |
+
refresh_button2 = gr.Button("To update", variant="primary", size='sm')
|
| 635 |
+
record_button.change(fn=save_to_wav, inputs=[record_button], outputs=[input_audio0])
|
| 636 |
+
record_button.change(fn=change_choices2, inputs=[], outputs=[input_audio0])
|
| 637 |
+
|
| 638 |
+
with gr.Column():
|
| 639 |
+
vc_output2 = gr.Audio(
|
| 640 |
+
label="Final result! (Click on the three dots to download the audio)",
|
| 641 |
+
type='filepath',
|
| 642 |
+
interactive=False,
|
| 643 |
+
)
|
| 644 |
+
|
| 645 |
+
with gr.Accordion('Edge-TTS', open=True):
|
| 646 |
+
with gr.Column():
|
| 647 |
+
ilariaid=gr.Dropdown(label="Voice:", choices=ilariavoices, value="Brazilian-Antonio- (Male)")
|
| 648 |
+
ilariatext = gr.Textbox(label="Digite o seu Texto", interactive=True, value="Isso é um teste.")
|
| 649 |
+
ilariatts_button = gr.Button(value="To speak")
|
| 650 |
+
ilariatts_button.click(fn=ilariaTTS, inputs=[ilariatext, ilariaid], outputs=[record_button, input_audio0])
|
| 651 |
+
|
| 652 |
+
with gr.Accordion("Index Configuration", open=False):
|
| 653 |
+
|
| 654 |
+
file_index1 = gr.Dropdown(
|
| 655 |
+
label="3. Choose the index file (if it was not found automatically).",
|
| 656 |
+
choices=get_indexes(),
|
| 657 |
+
value=get_index(),
|
| 658 |
+
interactive=True,
|
| 659 |
+
)
|
| 660 |
+
sid0.change(fn=match_index, inputs=[sid0],outputs=[file_index1])
|
| 661 |
+
refresh_button.click(
|
| 662 |
+
fn=change_choices, inputs=[], outputs=[sid0, file_index1]
|
| 663 |
+
)
|
| 664 |
+
index_rate1 = gr.Slider(
|
| 665 |
+
minimum=0,
|
| 666 |
+
maximum=1,
|
| 667 |
+
label=i18n("Search Feature Ratio"),
|
| 668 |
+
value=0.66,
|
| 669 |
+
interactive=True,
|
| 670 |
+
)
|
| 671 |
+
|
| 672 |
+
with gr.Accordion("advanced options", open=False):
|
| 673 |
+
f0method0 = gr.Radio(
|
| 674 |
+
label="Optional: Change the pitch extraction algorithm. Extraction methods are ranked from “worst quality” to “best quality”. If you don't know what you're doing, quit rmvpe.",
|
| 675 |
+
choices=["pm", "dio", "crepe-tiny", "mangio-crepe-tiny", "crepe", "harvest", "mangio-crepe", "rmvpe"],
|
| 676 |
+
value="rmvpe",
|
| 677 |
+
interactive=True,
|
| 678 |
+
)
|
| 679 |
+
|
| 680 |
+
crepe_hop_length = gr.Slider(
|
| 681 |
+
minimum=1,
|
| 682 |
+
maximum=512,
|
| 683 |
+
step=1,
|
| 684 |
+
label="Mangio-Crepe Hop Length. Higher numbers will reduce the chance of extreme pitch changes but lower numbers will increase accuracy. 64-192 is a good range to experiment with.",
|
| 685 |
+
value=120,
|
| 686 |
+
interactive=True,
|
| 687 |
+
visible=False,
|
| 688 |
+
)
|
| 689 |
+
f0method0.change(fn=whethercrepeornah, inputs=[f0method0], outputs=[crepe_hop_length])
|
| 690 |
+
filter_radius0 = gr.Slider(
|
| 691 |
+
minimum=0,
|
| 692 |
+
maximum=7,
|
| 693 |
+
label=i18n(">=3, use median filtering on the harvest tone recognition result, the value is the filter radius, which may weaken the muted sound."),
|
| 694 |
+
value=3,
|
| 695 |
+
step=1,
|
| 696 |
+
interactive=True,
|
| 697 |
+
)
|
| 698 |
+
resample_sr0 = gr.Slider(
|
| 699 |
+
minimum=0,
|
| 700 |
+
maximum=48000,
|
| 701 |
+
label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
|
| 702 |
+
value=0,
|
| 703 |
+
step=1,
|
| 704 |
+
interactive=True,
|
| 705 |
+
visible=False
|
| 706 |
+
)
|
| 707 |
+
rms_mix_rate0 = gr.Slider(
|
| 708 |
+
minimum=0,
|
| 709 |
+
maximum=1,
|
| 710 |
+
label=i18n("The volume envelope of the input source overrides the fusing rate of the output volume envelope. The closer it is to 1, the more output envelope is used."),
|
| 711 |
+
value=0.21,
|
| 712 |
+
interactive=True,
|
| 713 |
+
)
|
| 714 |
+
protect0 = gr.Slider(
|
| 715 |
+
minimum=0,
|
| 716 |
+
maximum=0.5,
|
| 717 |
+
label=i18n("Protect voiceless consonants and breath sounds to avoid artifacts such as electronic sound breakdown. Do not activate when it reaches 0.5. Lower it to increase protection, but may reduce the indexing effect."),
|
| 718 |
+
value=0.33,
|
| 719 |
+
step=0.01,
|
| 720 |
+
interactive=True,
|
| 721 |
+
)
|
| 722 |
+
formanting = gr.Checkbox(
|
| 723 |
+
value=bool(DoFormant),
|
| 724 |
+
label="[EXPERIMENTAL] Formant shift inference audio",
|
| 725 |
+
info="Used for conversions from male to female and vice versa",
|
| 726 |
+
interactive=True,
|
| 727 |
+
visible=True,
|
| 728 |
+
)
|
| 729 |
+
|
| 730 |
+
formant_preset = gr.Dropdown(
|
| 731 |
+
value='',
|
| 732 |
+
choices=get_fshift_presets(),
|
| 733 |
+
label="browse presets for formanting",
|
| 734 |
+
visible=bool(DoFormant),
|
| 735 |
+
)
|
| 736 |
+
formant_refresh_button = gr.Button(
|
| 737 |
+
value='\U0001f504',
|
| 738 |
+
visible=bool(DoFormant),
|
| 739 |
+
variant='primary',
|
| 740 |
+
)
|
| 741 |
+
|
| 742 |
+
qfrency = gr.Slider(
|
| 743 |
+
value=Quefrency,
|
| 744 |
+
info="Default value is 1.0",
|
| 745 |
+
label="Quefrency for formant shifting",
|
| 746 |
+
minimum=0.0,
|
| 747 |
+
maximum=16.0,
|
| 748 |
+
step=0.1,
|
| 749 |
+
visible=bool(DoFormant),
|
| 750 |
+
interactive=True,
|
| 751 |
+
)
|
| 752 |
+
tmbre = gr.Slider(
|
| 753 |
+
value=Timbre,
|
| 754 |
+
info="Default value is 1.0",
|
| 755 |
+
label="Timbre for formant shifting",
|
| 756 |
+
minimum=0.0,
|
| 757 |
+
maximum=16.0,
|
| 758 |
+
step=0.1,
|
| 759 |
+
visible=bool(DoFormant),
|
| 760 |
+
interactive=True,
|
| 761 |
+
)
|
| 762 |
+
|
| 763 |
+
formant_preset.change(fn=preset_apply, inputs=[formant_preset, qfrency, tmbre], outputs=[qfrency, tmbre])
|
| 764 |
+
frmntbut = gr.Button("Apply", variant="primary", visible=bool(DoFormant))
|
| 765 |
+
formanting.change(fn=formant_enabled,inputs=[formanting,qfrency,tmbre,frmntbut,formant_preset,formant_refresh_button],outputs=[formanting,qfrency,tmbre,frmntbut,formant_preset,formant_refresh_button])
|
| 766 |
+
frmntbut.click(fn=formant_apply,inputs=[qfrency, tmbre], outputs=[qfrency, tmbre])
|
| 767 |
+
formant_refresh_button.click(fn=update_fshift_presets,inputs=[formant_preset, qfrency, tmbre],outputs=[formant_preset, qfrency, tmbre])
|
| 768 |
+
|
| 769 |
+
with gr.Row():
|
| 770 |
+
vc_output1 = gr.Textbox("")
|
| 771 |
+
f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"), visible=False)
|
| 772 |
+
|
| 773 |
+
but0.click(
|
| 774 |
+
vc_single,
|
| 775 |
+
[
|
| 776 |
+
spk_item,
|
| 777 |
+
input_audio0,
|
| 778 |
+
vc_transform0,
|
| 779 |
+
f0_file,
|
| 780 |
+
f0method0,
|
| 781 |
+
file_index1,
|
| 782 |
+
index_rate1,
|
| 783 |
+
filter_radius0,
|
| 784 |
+
resample_sr0,
|
| 785 |
+
rms_mix_rate0,
|
| 786 |
+
protect0,
|
| 787 |
+
crepe_hop_length
|
| 788 |
+
],
|
| 789 |
+
[vc_output1, vc_output2],
|
| 790 |
+
)
|
| 791 |
+
|
| 792 |
+
with gr.TabItem("Download new templates"):
|
| 793 |
+
with gr.Row():
|
| 794 |
+
url=gr.Textbox(label="Huggingface Link:")
|
| 795 |
+
with gr.Row():
|
| 796 |
+
model = gr.Textbox(label="Models Name:")
|
| 797 |
+
download_button=gr.Button("Dowoad")
|
| 798 |
+
with gr.Row():
|
| 799 |
+
status_bar=gr.Textbox(label="Status download")
|
| 800 |
+
download_button.click(fn=download_from_url, inputs=[url, model], outputs=[status_bar])
|
| 801 |
+
|
| 802 |
+
gr.Markdown("<h4> Easy GUI (English) </h4>")
|
| 803 |
+
gr.Markdown(
|
| 804 |
+
"""
|
| 805 |
+
original by Rejekts improved by AsukaDev
|
| 806 |
+
"""
|
| 807 |
+
)
|
| 808 |
+
app.launch(share=True, quiet=False)
|