RVC: RMVPE support

This commit is contained in:
w-okada 2023-07-18 23:02:06 +09:00
parent 257d99e355
commit 1d54687577
3 changed files with 55 additions and 1 deletions

View File

@ -124,8 +124,10 @@ class Pipeline(object):
else:
pitch = None
pitchf = None
except IndexError:
except IndexError as e: # NOQA
# print(e)
# import traceback
# traceback.print_exc()
raise NotEnoughDataExtimateF0()
# tensor型調整

View File

@ -5,6 +5,7 @@ from voice_changer.RVC.pitchExtractor.DioPitchExtractor import DioPitchExtractor
from voice_changer.RVC.pitchExtractor.HarvestPitchExtractor import HarvestPitchExtractor
from voice_changer.RVC.pitchExtractor.CrepePitchExtractor import CrepePitchExtractor
from voice_changer.RVC.pitchExtractor.PitchExtractor import PitchExtractor
from voice_changer.RVC.pitchExtractor.RMVPEPitchExtractor import RMVPEPitchExtractor
from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
@ -37,6 +38,8 @@ class PitchExtractorManager(Protocol):
return CrepeOnnxPitchExtractor(pitchExtractorType, cls.params.crepe_onnx_tiny, gpu)
elif pitchExtractorType == "crepe_full":
return CrepeOnnxPitchExtractor(pitchExtractorType, cls.params.crepe_onnx_full, gpu)
elif pitchExtractorType == "rmvpe":
return RMVPEPitchExtractor(cls.params.rmvpe, gpu)
else:
# return hubert as default
print("[Voice Changer] PitchExctractor not found", pitchExtractorType)

View File

@ -0,0 +1,49 @@
import torch
import numpy as np
from const import PitchExtractorType
from voice_changer.DiffusionSVC.pitchExtractor.PitchExtractor import PitchExtractor
from voice_changer.DiffusionSVC.pitchExtractor.rmvpe.rmvpe import RMVPE
class RMVPEPitchExtractor(PitchExtractor):
def __init__(self, file: str, gpu: int):
super().__init__()
self.pitchExtractorType: PitchExtractorType = "rmvpe"
self.f0_min = 50
self.f0_max = 1100
self.f0_mel_min = 1127 * np.log(1 + self.f0_min / 700)
self.f0_mel_max = 1127 * np.log(1 + self.f0_max / 700)
self.uv_interp = True
self.input_sr = -1
if torch.cuda.is_available() and gpu >= 0:
self.device = torch.device("cuda:" + str(torch.cuda.current_device()))
else:
self.device = torch.device("cpu")
self.rmvpe = RMVPE(model_path=file, is_half=False, device=self.device)
def extract(self, audio, pitchf, f0_up_key, sr, window, silence_front=0):
hop_size = 160 # RMVPE固定
offset_frame_number = silence_front * 16000
start_frame = int(offset_frame_number / hop_size) # frame
real_silence_front = start_frame * hop_size / 16000 # 秒
audio = audio[int(np.round(real_silence_front * 16000)):]
f0 = self.rmvpe.infer_from_audio_t(audio, thred=0.03)
f0 = f0 * 2 ** (float(f0_up_key) / 12)
pitchf[-f0.shape[0]:] = f0[:pitchf.shape[0]]
f0 = pitchf
f0bak = f0.copy()
f0_mel = 1127 * np.log(1 + f0 / 700)
f0_mel[f0_mel > 0] = (f0_mel[f0_mel > 0] - self.f0_mel_min) * 254 / (
self.f0_mel_max - self.f0_mel_min
) + 1
f0_mel[f0_mel <= 1] = 1
f0_mel[f0_mel > 255] = 255
f0_coarse = np.rint(f0_mel).astype(int)
return f0_coarse, f0bak