add type declarations

This commit is contained in:
Ftps
2023-11-19 04:13:34 +09:00
parent 7f551b6787
commit 902654a1eb
2 changed files with 44 additions and 56 deletions

View File

@@ -18,22 +18,24 @@ from rvc.lib.infer_pack.models import (
from rvc.modules.vc.pipeline import Pipeline from rvc.modules.vc.pipeline import Pipeline
from rvc.modules.vc.utils import * from rvc.modules.vc.utils import *
logger: logging.Logger = logging.getLogger(__name__)
class VC: class VC:
def __init__(self, config): def __init__(self):
self.n_spk = None self.n_spk: any = None
self.tgt_sr = None self.tgt_sr: int | None = None
self.net_g = None self.net_g = None
self.pipeline = None self.pipeline: Pipeline | None = None
self.cpt = None self.cpt: OrderedDict | None = None
self.version = None self.version: str | None = None
self.if_f0 = None self.if_f0: int | None = None
self.version = None self.version: str | None = None
self.hubert_model = None self.hubert_model: any = None
self.config = config self.config = Config()
def get_vc(self, sid, *to_return_protect): def get_vc(self, sid: str, *to_return_protect: int):
logger.info("Get sid: " + sid) logger.info("Get sid: " + sid)
return_protect = [ return_protect = [
@@ -84,18 +86,18 @@ class VC:
def vc_single( def vc_single(
self, self,
sid, sid: int,
input_audio_path, input_audio_path: Path,
f0_up_key, f0_up_key: int = 0,
f0_file, f0_method: str = "rmvpe",
f0_method, f0_file: Path | None = None,
file_index, index_file: Path | None = None,
file_index2, index_rate: float = 0.75,
index_rate, filter_radius: int = 3,
filter_radius, resample_sr: int = 0,
resample_sr, rms_mix_rate: float = 0.25,
rms_mix_rate, protect: float = 0.33,
protect, hubert_path: str | None = None,
): ):
if input_audio_path is None: if input_audio_path is None:
return "You need to upload an audio", None return "You need to upload an audio", None
@@ -108,21 +110,7 @@ class VC:
times = {"npy": 0, "f0": 0, "infer": 0} times = {"npy": 0, "f0": 0, "infer": 0}
if self.hubert_model is None: if self.hubert_model is None:
self.hubert_model = load_hubert(self.config) self.hubert_model = load_hubert(self.config, hubert_path)
if file_index:
file_index = (
file_index.strip(" ")
.strip('"')
.strip("\n")
.strip('"')
.strip(" ")
.replace("trained", "added")
)
elif file_index2:
file_index = file_index2
else:
file_index = "" # 防止小白写错,自动帮他替换掉
audio_opt = self.pipeline.pipeline( audio_opt = self.pipeline.pipeline(
self.hubert_model, self.hubert_model,
@@ -133,7 +121,7 @@ class VC:
times, times,
f0_up_key, f0_up_key,
f0_method, f0_method,
file_index, index_file,
index_rate, index_rate,
self.if_f0, self.if_f0,
filter_radius, filter_radius,
@@ -156,20 +144,20 @@ class VC:
def vc_multi( def vc_multi(
self, self,
sid, sid: int,
dir_path, paths: list,
opt_root, opt_root: Path,
paths, f0_up_key: int = 0,
f0_up_key, f0_method: str = "rmvpe",
f0_method, f0_file: Path | None = None,
file_index, index_file: Path | None = None,
file_index2, index_rate: float = 0.75,
index_rate, filter_radius: int = 3,
filter_radius, resample_sr: int = 0,
resample_sr, rms_mix_rate: float = 0.25,
rms_mix_rate, protect: float = 0.33,
protect, output_format: str = "wav",
format1, hubert_path: str | None = None,
): ):
try: try:
os.makedirs(opt_root, exist_ok=True) os.makedirs(opt_root, exist_ok=True)

View File

@@ -18,8 +18,7 @@ import torch.nn.functional as F
import torchcrepe import torchcrepe
from scipy import signal from scipy import signal
now_dir = os.getcwd() logger: logging.Logger = logging.getLogger(__name__)
sys.path.append(now_dir)
bh, ah = signal.butter(N=5, Wn=48, btype="high", fs=16000) bh, ah = signal.butter(N=5, Wn=48, btype="high", fs=16000)
@@ -300,7 +299,8 @@ class Pipeline(object):
f0_file=None, f0_file=None,
): ):
if ( if (
file_index != "" file_index
and file_index != ""
# and file_big_npy != "" # and file_big_npy != ""
# and os.path.exists(file_big_npy) == True # and os.path.exists(file_big_npy) == True
and os.path.exists(file_index) and os.path.exists(file_index)