mirror of
https://github.com/storytold/storyteller-ml.git
synced 2026-10-29 09:18:21 +00:00
Merge pull request #20 from storytold/brandon-rmvpe-support
Rmvpe support
This commit is contained in:
@@ -119,6 +119,8 @@ parser.add_argument('--model_path', type=str, help='path to the .pth file', requ
|
|||||||
parser.add_argument('--model_index_path', type=str, help='path to the .index file (empty string for none)', required=False, default='')
|
parser.add_argument('--model_index_path', type=str, help='path to the .index file (empty string for none)', required=False, default='')
|
||||||
parser.add_argument('--hubert_model_path', type=str, help='path to the hubert model .pth file (default hubert_base.pt)',
|
parser.add_argument('--hubert_model_path', type=str, help='path to the hubert model .pth file (default hubert_base.pt)',
|
||||||
required=False, default='hubert_base.pt')
|
required=False, default='hubert_base.pt')
|
||||||
|
parser.add_argument('--rmvpe_model_path', type=str, help='path to the RMVPE model .pth file (default rmvpe.pt)',
|
||||||
|
required=False, default='rmvpe.pt')
|
||||||
|
|
||||||
parser.add_argument('--input_audio_filename', type=str, help='source audio file', required=True)
|
parser.add_argument('--input_audio_filename', type=str, help='source audio file', required=True)
|
||||||
parser.add_argument('--output_audio_filename', type=str, help='result audio file', required=True)
|
parser.add_argument('--output_audio_filename', type=str, help='result audio file', required=True)
|
||||||
@@ -130,7 +132,7 @@ parser.add_argument('--f0_up_key', type=str,
|
|||||||
help='the f0 key for the input audio file(default "0")',
|
help='the f0 key for the input audio file(default "0")',
|
||||||
required=False, default='0')
|
required=False, default='0')
|
||||||
parser.add_argument('--f0_method', type=str,
|
parser.add_argument('--f0_method', type=str,
|
||||||
help='f0 estimation method to use: harvest (default), crepe, or pm',
|
help='f0 estimation method to use: rmvpe (best), harvest (default), crepe, or pm',
|
||||||
required=False, default='harvest')
|
required=False, default='harvest')
|
||||||
parser.add_argument('--index_rate', type=float,
|
parser.add_argument('--index_rate', type=float,
|
||||||
help='The rate for the index (search feature ratio) (default 0.75)',
|
help='The rate for the index (search feature ratio) (default 0.75)',
|
||||||
@@ -168,6 +170,7 @@ resample_sr = args.resample_sr
|
|||||||
rms_mix_rate = args.rms_mix_rate
|
rms_mix_rate = args.rms_mix_rate
|
||||||
protect = args.protect
|
protect = args.protect
|
||||||
hubert_path = args.hubert_model_path
|
hubert_path = args.hubert_model_path
|
||||||
|
rmvpe_path = args.rmvpe_model_path
|
||||||
|
|
||||||
config = Config(device, is_half)
|
config = Config(device, is_half)
|
||||||
now_dir = os.getcwd()
|
now_dir = os.getcwd()
|
||||||
@@ -201,7 +204,7 @@ def load_hubert(hubert_path="hubert_base.pt"):
|
|||||||
hubert_model.eval()
|
hubert_model.eval()
|
||||||
|
|
||||||
|
|
||||||
def vc_single(sid, input_audio, f0_up_key, f0_file, f0_method, file_index, index_rate, hubert_path="hubert_base.pt"):
|
def vc_single(sid, input_audio, f0_up_key, f0_file, f0_method, file_index, index_rate, rmvpe_path, hubert_path="hubert_base.pt"):
|
||||||
global tgt_sr, net_g, vc, hubert_model, version
|
global tgt_sr, net_g, vc, hubert_model, version
|
||||||
if input_audio is None:
|
if input_audio is None:
|
||||||
return "You need to upload an audio", None
|
return "You need to upload an audio", None
|
||||||
@@ -218,6 +221,7 @@ def vc_single(sid, input_audio, f0_up_key, f0_file, f0_method, file_index, index
|
|||||||
sid,
|
sid,
|
||||||
audio,
|
audio,
|
||||||
input_audio,
|
input_audio,
|
||||||
|
rmvpe_path,
|
||||||
times,
|
times,
|
||||||
f0_up_key,
|
f0_up_key,
|
||||||
f0_method,
|
f0_method,
|
||||||
@@ -270,7 +274,7 @@ get_vc(model_path)
|
|||||||
|
|
||||||
file_path = input_path
|
file_path = input_path
|
||||||
wav_opt = vc_single(
|
wav_opt = vc_single(
|
||||||
0, file_path, f0up_key, None, f0method, index_path, index_rate, hubert_path
|
0, file_path, f0up_key, None, f0method, index_path, index_rate, rmvpe_path, hubert_path
|
||||||
)
|
)
|
||||||
out_path = opt_path
|
out_path = opt_path
|
||||||
wavfile.write(out_path, tgt_sr, wav_opt)
|
wavfile.write(out_path, tgt_sr, wav_opt)
|
||||||
|
|||||||
@@ -27,6 +27,18 @@ def cache_harvest_f0(input_audio_path, fs, f0max, f0min, frame_period):
|
|||||||
f0 = pyworld.stonemask(audio, f0, t, fs)
|
f0 = pyworld.stonemask(audio, f0, t, fs)
|
||||||
return f0
|
return f0
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
|
def cache_dio_f0(input_audio_path, fs, f0max, f0min, frame_period):
|
||||||
|
audio = input_audio_path2wav[input_audio_path]
|
||||||
|
f0, t = pyworld.dio(
|
||||||
|
audio,
|
||||||
|
fs=fs,
|
||||||
|
f0_ceil=f0max,
|
||||||
|
f0_floor=f0min,
|
||||||
|
frame_period=frame_period,
|
||||||
|
)
|
||||||
|
f0 = pyworld.stonemask(audio, f0, t, fs)
|
||||||
|
return f0
|
||||||
|
|
||||||
def change_rms(data1, sr1, data2, sr2, rate): # 1是输入音频,2是输出音频,rate是2的占比
|
def change_rms(data1, sr1, data2, sr2, rate): # 1是输入音频,2是输出音频,rate是2的占比
|
||||||
# print(data1.max(),data2.max())
|
# print(data1.max(),data2.max())
|
||||||
@@ -72,6 +84,7 @@ class VC(object):
|
|||||||
def get_f0(
|
def get_f0(
|
||||||
self,
|
self,
|
||||||
input_audio_path,
|
input_audio_path,
|
||||||
|
rmvpe_model_path,
|
||||||
x,
|
x,
|
||||||
p_len,
|
p_len,
|
||||||
f0_up_key,
|
f0_up_key,
|
||||||
@@ -106,6 +119,11 @@ class VC(object):
|
|||||||
f0 = cache_harvest_f0(input_audio_path, self.sr, f0_max, f0_min, 10)
|
f0 = cache_harvest_f0(input_audio_path, self.sr, f0_max, f0_min, 10)
|
||||||
if filter_radius > 2:
|
if filter_radius > 2:
|
||||||
f0 = signal.medfilt(f0, 3)
|
f0 = signal.medfilt(f0, 3)
|
||||||
|
elif f0_method == "dio":
|
||||||
|
input_audio_path2wav[input_audio_path] = x.astype(np.double)
|
||||||
|
f0 = cache_dio_f0(input_audio_path, self.sr, f0_max, f0_min, 10)
|
||||||
|
if filter_radius > 2:
|
||||||
|
f0 = signal.medfilt(f0, 3)
|
||||||
elif f0_method == "crepe":
|
elif f0_method == "crepe":
|
||||||
model = "full"
|
model = "full"
|
||||||
# Pick a batch size that doesn't cause memory errors on your gpu
|
# Pick a batch size that doesn't cause memory errors on your gpu
|
||||||
@@ -132,7 +150,8 @@ class VC(object):
|
|||||||
from lib.rmvpe import RMVPE
|
from lib.rmvpe import RMVPE
|
||||||
print("loading rmvpe model")
|
print("loading rmvpe model")
|
||||||
self.model_rmvpe = RMVPE(
|
self.model_rmvpe = RMVPE(
|
||||||
"rmvpe.pt", is_half=self.is_half, device=self.device
|
#"rmvpe.pt", is_half=self.is_half, device=self.device
|
||||||
|
rmvpe_model_path, is_half=self.is_half, device=self.device
|
||||||
)
|
)
|
||||||
|
|
||||||
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
|
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
|
||||||
@@ -275,6 +294,7 @@ class VC(object):
|
|||||||
sid,
|
sid,
|
||||||
audio,
|
audio,
|
||||||
input_audio_path,
|
input_audio_path,
|
||||||
|
rmvpe_model_path,
|
||||||
times,
|
times,
|
||||||
f0_up_key,
|
f0_up_key,
|
||||||
f0_method,
|
f0_method,
|
||||||
@@ -344,6 +364,7 @@ class VC(object):
|
|||||||
if if_f0 == 1:
|
if if_f0 == 1:
|
||||||
pitch, pitchf = self.get_f0(
|
pitch, pitchf = self.get_f0(
|
||||||
input_audio_path,
|
input_audio_path,
|
||||||
|
rmvpe_model_path,
|
||||||
audio_pad,
|
audio_pad,
|
||||||
p_len,
|
p_len,
|
||||||
f0_up_key,
|
f0_up_key,
|
||||||
|
|||||||
Reference in New Issue
Block a user