Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNeodev authored Dec 18, 2024
1 parent b309184 commit 5c0ad21
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 54 deletions.
2 changes: 1 addition & 1 deletion rvc_inferpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .infer import infer_audio, dl_model, download_rvc_model
from .infer import infer_audio, dl_model
19 changes: 17 additions & 2 deletions rvc_inferpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def infer_audio_cli():
parser = argparse.ArgumentParser(description="RVC CLI.")
parser = argparse.ArgumentParser(description="RVC INFERPY CLI VER.")
parser.add_argument("--model_name", type=str, help="Name of the model.")
parser.add_argument("--audio_path", type=str, help="Path to the input audio file.")
parser.add_argument(
Expand Down Expand Up @@ -71,9 +71,22 @@ def infer_audio_cli():
parser.add_argument(
"--resample_sr", type=int, default=0, help="Resample sample rate."
)

parser.add_argument(
"--hubert_model_path",
type=str,
default="hubert_base.pt",
help="Path to Hubert model.",
)
parser.add_argument(
"--rmvpe_model_path", type=str, default="rmvpe.pt", help="Path to RMVPE model."
)
parser.add_argument(
"--fcpe_model_path", type=str, default="fcpe.pt", help="Path to FCPE model."
)
args = parser.parse_args()

os.environ["rmvpe_model_path"] = args.rmvpe_model_path
os.environ["fcpe_model_path"] = args.fcpe_model_path
configs = Configs("cuda:0", True)
vc = VC(configs)
pth_path, index_path = get_model(args.model_name)
Expand Down Expand Up @@ -113,6 +126,7 @@ def infer_audio_cli():
args.min_pitch,
args.max_pitch,
args.f0_autotune,
args.hubert_model_path,
)
if inference_info[0] == "Success.":
print("Inference ran successfully.")
Expand Down Expand Up @@ -148,6 +162,7 @@ def infer_audio_cli():
args.min_pitch,
args.max_pitch,
args.f0_autotune,
args.hubert_model_path,
)
if inference_info[0] == "Success.":
print("Inference ran successfully.")
Expand Down
64 changes: 42 additions & 22 deletions rvc_inferpy/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,8 @@
adjust_audio_lengths,
combine_silence_nonsilent,
)
from rvc_inferpy.config_loader import *
import torch
from pathlib import Path
import requests
import os
import zipfile
import shutil
import urllib.request
import gdown

models_dir = "models"


validate_config_and_files()

BaseLoader(hubert_path=hubert_model_path, rmvpe_path=rmvpe_model_path)
rvcbasdl = lambda: print(
"RVC-based loader initialized."
) # Replace with the actual function
rvcbasdl()


class Configs:
Expand Down Expand Up @@ -95,6 +77,43 @@ def get_model(voice_model):
)


BASE_DIR = Path(os.getcwd())
sys.path.append(str(BASE_DIR))

files_to_check = ["hubert_base.pt", "rmvpe.pt", "fcpe.pt"]

missing_files = [file for file in files_to_check if not (BASE_DIR / file).exists()]


def dl_model(link, model_name, dir_name):
url = f"{link}/{model_name}"
response = requests.get(url, stream=True)
response.raise_for_status()

target_path = dir_name / model_name
target_path.parent.mkdir(
parents=True, exist_ok=True
) # Create the directory if it doesn't exist

with open(target_path, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)

print(f"{model_name} downloaded successfully!")


if missing_files:
RVC_DOWNLOAD_LINK = "https://huggingface.co/theNeofr/rvc-base/resolve/main" # Replace with the actual download link

for model in missing_files:
print(f"Downloading {model}...")
dl_model(RVC_DOWNLOAD_LINK, model, BASE_DIR)

print("All missing models have been downloaded!")
else:
pass


def infer_audio(
model_name,
audio_path,
Expand All @@ -118,11 +137,12 @@ def infer_audio(
f0_autotune=False,
audio_format="wav",
resample_sr=0,
hubert_model_path=hubert_model_path,
rmvpe_model_path=rmvpe_model_path,
fcpe_model_path=fcpe_model_path,
hubert_model_path="hubert_base.pt",
rmvpe_model_path="rmvpe.pt",
fcpe_model_path="fcpe.pt",
):

os.environ["rmvpe_model_path"] = rmvpe_model_path
os.environ["fcpe_model_path"] = fcpe_model_path
configs = Configs("cuda:0", True)
vc = VC(configs)
pth_path, index_path = get_model(model_name)
Expand Down
15 changes: 2 additions & 13 deletions rvc_inferpy/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@
import glob
from shutil import move
from fairseq import checkpoint_utils
from rvc_inferpy.config_loader import *


validate_config_and_files()

BaseLoader(hubert_path=hubert_model_path, rmvpe_path=rmvpe_model_path)
rvcbasdl = lambda: print(
"RVC-based loader initialized."
) # Replace with the actual function
rvcbasdl()


sup_audioext = {
"wav",
Expand Down Expand Up @@ -239,7 +228,7 @@ def vc_single_dont_save(
f0_min,
f0_max,
f0_autotune,
hubert_model_path=hubert_model_path,
hubert_model_path="hubert_base.pt",
):
"""
Performs inference without saving
Expand Down Expand Up @@ -408,7 +397,7 @@ def vc_single(
f0_min,
f0_max,
f0_autotune,
hubert_model_path=hubert_model_path,
hubert_model_path="hubert_base.pt",
):
"""
Performs inference with saving
Expand Down
23 changes: 7 additions & 16 deletions rvc_inferpy/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@
import torch
from rvc_inferpy.infer_list.rmvpe import RMVPE
from rvc_inferpy.infer_list.fcpe import FCPE
from rvc_inferpy.config_loader import *

validate_config_and_files()

BaseLoader(hubert_path=hubert_model_path, rmvpe_path=rmvpe_model_path)
rvcbasdl = lambda: print(
"RVC-based loader initialized."
) # Replace with the actual function
rvcbasdl()


@lru_cache
Expand Down Expand Up @@ -265,11 +256,11 @@ def get_f0_pyin_computation(self, x, f0_min, f0_max):

def get_rmvpe(self, x, *args, **kwargs):
if not hasattr(self, "model_rmvpe"):
from rvc_inferpy.infer_list.rmvpe import RMVPE
from lib.infer.infer_libs.rmvpe import RMVPE

logger.info(f"Loading rmvpe model, {os.environ['rmvpe_model_path']}")
self.model_rmvpe = RMVPE(
rmvpe_model_path,
os.environ["rmvpe_model_path"],
is_half=self.is_half,
device=self.device,
)
Expand All @@ -284,11 +275,11 @@ def get_rmvpe(self, x, *args, **kwargs):

def get_pitch_dependant_rmvpe(self, x, f0_min=1, f0_max=40000, *args, **kwargs):
if not hasattr(self, "model_rmvpe"):
from rvc_inferpy.infer_list.rmvpe import RMVPE
from lib.infer.infer_libs.rmvpe import RMVPE

logger.info(f"Loading rmvpe model, {os.environ['rmvpe_model_path']}")
self.model_rmvpe = RMVPE(
rmvpe_model_path,
os.environ["rmvpe_model_path"],
is_half=self.is_half,
device=self.device,
)
Expand All @@ -304,7 +295,7 @@ def get_pitch_dependant_rmvpe(self, x, f0_min=1, f0_max=40000, *args, **kwargs):

def get_fcpe(self, x, f0_min, f0_max, p_len, *args, **kwargs):
self.model_fcpe = FCPE(
fcpe_model_path,
os.environ["fcpe_model_path"],
f0_min=f0_min,
f0_max=f0_max,
dtype=torch.float32,
Expand Down Expand Up @@ -534,11 +525,11 @@ def get_f0(
)
elif f0_method == "rmvpe":
if not hasattr(self, "model_rmvpe"):
from rvc_inferpy.infer_list.rmvpe import RMVPE
from lib.infer.infer_libs.rmvpe import RMVPE

logger.info(f"Loading rmvpe model, {os.environ['rmvpe_model_path']}")
self.model_rmvpe = RMVPE(
rmvpe_model_path,
os.environ["rmvpe_model_path"],
is_half=self.is_half,
device=self.device,
)
Expand Down

0 comments on commit 5c0ad21

Please sign in to comment.