From aa37b92bd3fe2accc1c15acd235c98976a76a9aa Mon Sep 17 00:00:00 2001 From: Ftps <63702646+Tps-F@users.noreply.github.com> Date: Mon, 28 Aug 2023 00:36:56 +0900 Subject: [PATCH] rewrite infer_batch_rvc.py --- tools/infer_batch_rvc.py | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tools/infer_batch_rvc.py diff --git a/tools/infer_batch_rvc.py b/tools/infer_batch_rvc.py new file mode 100644 index 0000000..b8d73e7 --- /dev/null +++ b/tools/infer_batch_rvc.py @@ -0,0 +1,70 @@ +import argparse +import os +import sys + +print("Command-line arguments:", sys.argv) + +now_dir = os.getcwd() +sys.path.append(now_dir) +import sys + +import tqdm as tq +from dotenv import load_dotenv +from scipy.io import wavfile + +from configs.config import Config +from infer.modules.vc.modules import VC + + +def args() -> tuple: + parser = argparse.ArgumentParser() + parser.add_argument("--f0up_key", type=int, default=0) + parser.add_argument("--input_path", type=str, help="input path") + parser.add_argument("--index_path", type=str, help="index path") + parser.add_argument("--f0method", type=str, default="harvest", help="harvest or pm") + parser.add_argument("--opt_path", type=str, help="opt path") + parser.add_argument("--model_name", type=str, help="store in assets/weight_root") + parser.add_argument("--index_rate", type=float, default=0.66, help="index rate") + parser.add_argument("--device", type=str, help="device") + parser.add_argument("--is_half", type=bool, help="use half -> True") + parser.add_argument("--filter_radius", type=int, default=3, help="filter radius") + parser.add_argument("--resample_sr", type=int, default=0, help="resample sr") + parser.add_argument("--rms_mix_rate", type=float, default=1, help="rms mix rate") + parser.add_argument("--protect", type=float, default=0.33, help="protect") + + args = parser.parse_args() + sys.argv = sys.argv[:1] + + return args + + +def main(): + vc.get_vc(args.model_name) + audios = os.listdir(args.input_path) + for file in tq.tqdm(audios): + if file.endswith(".wav"): + file_path = os.path.join(args.input_path, file) + _, wav_opt = vc.vc_single( + 0, + file_path, + args.f0up_key, + None, + args.f0method, + args.index_path, + None, + args.index_rate, + args.filter_radius, + args.resample_sr, + args.rms_mix_rate, + args.protect, + ) + out_path = os.path.join(args.opt_path, file) + wavfile.write(out_path, vc.tgt_sr, wav_opt[1]) + + +if __name__ == "__main__": + load_dotenv() + args = args() + config = Config() + vc = VC(config) + main()