add inference cli
This commit is contained in:
30
rvc/cli/cli.py
Normal file
30
rvc/cli/cli.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import re
|
||||
from typing import Optional, Pattern
|
||||
|
||||
import click
|
||||
|
||||
from rvc.cli.handler.infer import infer
|
||||
from rvc.cli.handler.train import train
|
||||
from rvc.cli.handler.uvr5 import uvr
|
||||
|
||||
from rvc.cli.utils.dlmodel import dlmodel
|
||||
from rvc.cli.utils.env import env
|
||||
from rvc.cli.utils.initialize import initialize
|
||||
|
||||
|
||||
@click.group(
|
||||
context_settings={"help_option_names": ["-h", "--help"]},
|
||||
help="rvc cli feature list",
|
||||
)
|
||||
def cli():
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli.add_command(infer)
|
||||
cli.add_command(train)
|
||||
cli.add_command(uvr)
|
||||
cli.add_command(dlmodel)
|
||||
cli.add_command(env)
|
||||
cli.add_command(initialize)
|
||||
cli()
|
||||
131
rvc/cli/handler/infer.py
Normal file
131
rvc/cli/handler/infer.py
Normal file
@@ -0,0 +1,131 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
from dotenv import load_dotenv
|
||||
from scipy.io import wavfile
|
||||
|
||||
from rvc.modules.vc.modules import VC
|
||||
|
||||
|
||||
logging.getLogger("numba").setLevel(logging.WARNING)
|
||||
|
||||
|
||||
@click.command(
|
||||
context_settings={"help_option_names": ["-h", "--help"]},
|
||||
help="inference audio",
|
||||
)
|
||||
@click.option(
|
||||
"-m",
|
||||
"--modelPath",
|
||||
is_flag=False,
|
||||
type=str,
|
||||
help="Model path or filename (reads in the directory set in env)",
|
||||
required=True,
|
||||
)
|
||||
@click.option(
|
||||
"-i",
|
||||
"--inputPath",
|
||||
is_flag=False,
|
||||
type=Path,
|
||||
help="input audio path or folder",
|
||||
required=True,
|
||||
)
|
||||
@click.option(
|
||||
"-o",
|
||||
"--outputPath",
|
||||
is_flag=False,
|
||||
type=Path,
|
||||
help="output audio path or folder",
|
||||
required=True,
|
||||
)
|
||||
@click.option(
|
||||
"-s", "--sid", is_flag=False, type=int, help="Speaker/Singer id", default=0
|
||||
)
|
||||
@click.option("-fu", "--f0upkey", is_flag=False, type=int, help="Transpose", default=0)
|
||||
@click.option(
|
||||
"-fm",
|
||||
"--f0method",
|
||||
is_flag=False,
|
||||
type=str,
|
||||
help="Pitch extraction algorith",
|
||||
default="rmvpe",
|
||||
)
|
||||
@click.option(
|
||||
"-ff", "--f0file", is_flag=False, type=Path, help="F0 curve file (optional)"
|
||||
)
|
||||
@click.option("-if", "--indexFile", is_flag=False, type=Path, help="Feature index file")
|
||||
@click.option(
|
||||
"-ir",
|
||||
"--indexRate",
|
||||
is_flag=False,
|
||||
type=float,
|
||||
help="Search feature ratio",
|
||||
default=0.75,
|
||||
)
|
||||
@click.option(
|
||||
"-fr",
|
||||
"--filterRadius",
|
||||
is_flag=False,
|
||||
type=int,
|
||||
help="Apply median filtering",
|
||||
default=3,
|
||||
)
|
||||
@click.option(
|
||||
"-rsr",
|
||||
"--resamplesr",
|
||||
is_flag=False,
|
||||
type=int,
|
||||
help="Resample the output audio",
|
||||
default=0,
|
||||
)
|
||||
@click.option(
|
||||
"-rmr",
|
||||
"--rmsmixrate",
|
||||
is_flag=False,
|
||||
type=float,
|
||||
help="Adjust the volume envelope scaling",
|
||||
default=0.25,
|
||||
)
|
||||
@click.option(
|
||||
"-p",
|
||||
"--protect",
|
||||
is_flag=False,
|
||||
type=float,
|
||||
help="Protect voiceless consonants and breath sounds",
|
||||
default=0.33,
|
||||
)
|
||||
def infer(
|
||||
modelpath,
|
||||
inputpath,
|
||||
outputpath,
|
||||
sid,
|
||||
f0upkey,
|
||||
f0method,
|
||||
f0file,
|
||||
indexfile,
|
||||
indexrate,
|
||||
filterradius,
|
||||
resamplesr,
|
||||
rmsmixrate,
|
||||
protect,
|
||||
):
|
||||
load_dotenv()
|
||||
vc = VC()
|
||||
vc.get_vc(modelpath)
|
||||
tgt_sr, audio_opt, times, _ = vc.vc_single(
|
||||
sid,
|
||||
inputpath,
|
||||
f0upkey,
|
||||
f0method,
|
||||
f0file,
|
||||
indexfile,
|
||||
indexrate,
|
||||
filterradius,
|
||||
resamplesr,
|
||||
rmsmixrate,
|
||||
protect,
|
||||
)
|
||||
wavfile.write(outputpath, tgt_sr, audio_opt)
|
||||
click.echo(times)
|
||||
click.echo(f"Finish inference. Check {outputpath}")
|
||||
6
rvc/cli/handler/train.py
Normal file
6
rvc/cli/handler/train.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def train():
|
||||
pass
|
||||
6
rvc/cli/handler/uvr5.py
Normal file
6
rvc/cli/handler/uvr5.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def uvr():
|
||||
pass
|
||||
8
rvc/cli/utils/dlmodel.py
Normal file
8
rvc/cli/utils/dlmodel.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import urllib
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def dlmodel() -> None:
|
||||
# Download models [harvest, uvr5, and more ]
|
||||
pass
|
||||
13
rvc/cli/utils/env.py
Normal file
13
rvc/cli/utils/env.py
Normal file
@@ -0,0 +1,13 @@
|
||||
"""
|
||||
setup or cleanup enviroment file
|
||||
usage: rvc env [set / cleanup]
|
||||
Default: [nowDir/.env]
|
||||
|
||||
"""
|
||||
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def env():
|
||||
pass
|
||||
14
rvc/cli/utils/initialize.py
Normal file
14
rvc/cli/utils/initialize.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Uage: rvc init
|
||||
download model and setup environmmnt file
|
||||
|
||||
"""
|
||||
import click
|
||||
|
||||
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def initialize():
|
||||
pass
|
||||
@@ -82,7 +82,8 @@ class Config:
|
||||
action="store_true",
|
||||
help="torch_dml",
|
||||
)
|
||||
cmd_opts: argparse.Namespace = parser.parse_args()
|
||||
cmd_opts: argparse.Namespace
|
||||
cmd_opts, _ = parser.parse_known_args()
|
||||
|
||||
cmd_opts.port = cmd_opts.port if 0 <= cmd_opts.port <= 65535 else 7865
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class UVR:
|
||||
export_format,
|
||||
is_hp3=is_hp3,
|
||||
)
|
||||
infos.append(f"{os.path.basename(process_path)}->Success" )
|
||||
infos.append(f"{os.path.basename(process_path)}->Success")
|
||||
yield "\n".join(infos)
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.empty_cache()
|
||||
|
||||
@@ -45,7 +45,7 @@ class VC:
|
||||
to_return_protect[1] if self.if_f0 != 0 and to_return_protect else 0.33,
|
||||
]
|
||||
|
||||
person = f'{os.getenv("weight_root")}/{sid}'
|
||||
person = sid if os.path.exists(sid) else f'{os.getenv("weight_root")}/{sid}'
|
||||
logger.info(f"Loading: {person}")
|
||||
|
||||
self.cpt = torch.load(person, map_location="cpu")
|
||||
|
||||
Reference in New Issue
Block a user