Skip to content

Commit

Permalink
实时GUI支持rmvpe
Browse files Browse the repository at this point in the history
实时GUI支持rmvpe
  • Loading branch information
RVC-Boss authored Jul 11, 2023
1 parent c69cecb commit 0f9d2e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
18 changes: 11 additions & 7 deletions gui_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def load(self):
data["pm"]=data["f0method"]=="pm"
data["harvest"]=data["f0method"]=="harvest"
data["crepe"]=data["f0method"]=="crepe"
data["rmvpe"]=data["f0method"]=="rmvpe"
except:
with open("values1.json", "w") as j:
data = {
Expand All @@ -94,7 +95,7 @@ def load(self):
"block_time": "1",
"crossfade_length": "0.04",
"extra_time": "1",
"f0method": "harvest",
"f0method": "rmvpe",
}
return data

Expand Down Expand Up @@ -193,6 +194,7 @@ def launcher(self):
sg.Radio("pm","f0method",key="pm",default=data.get("pm","")==True),
sg.Radio("harvest","f0method",key="harvest",default=data.get("harvest","")==True),
sg.Radio("crepe","f0method",key="crepe",default=data.get("crepe","")==True),
sg.Radio("rmvpe","f0method",key="rmvpe",default=data.get("rmvpe","")==True),
],
],
title=i18n("常规设置"),
Expand Down Expand Up @@ -279,7 +281,7 @@ def event_handler(self):
"crossfade_length": values["crossfade_length"],
"extra_time": values["extra_time"],
"n_cpu": values["n_cpu"],
"f0method": ["pm","harvest","crepe"][[values["pm"],values["harvest"],values["crepe"]].index(True)],
"f0method": ["pm","harvest","crepe","rmvpe"][[values["pm"],values["harvest"],values["crepe"],values["rmvpe"]].index(True)],
}
with open("values1.json", "w") as j:
json.dump(settings, j)
Expand Down Expand Up @@ -312,7 +314,7 @@ def set_values(self, values):
self.config.O_noise_reduce = values["O_noise_reduce"]
self.config.index_rate = values["index_rate"]
self.config.n_cpu = values["n_cpu"]
self.config.f0method = ["pm","harvest","crepe"][[values["pm"],values["harvest"],values["crepe"]].index(True)]
self.config.f0method = ["pm","harvest","crepe","rmvpe"][[values["pm"],values["harvest"],values["crepe"],values["rmvpe"]].index(True)]
return True

def start_vc(self):
Expand Down Expand Up @@ -346,7 +348,7 @@ def start_vc(self):
self.fade_out_window: torch.Tensor = 1 - self.fade_in_window
self.resampler = tat.Resample(
orig_freq=self.config.samplerate, new_freq=16000, dtype=torch.float32
)
).to(device)
thread_vc = threading.Thread(target=self.soundinput)
thread_vc.start()

Expand Down Expand Up @@ -389,13 +391,15 @@ def audio_callback(
indata[i * hop_length : (i + 1) * hop_length] = 0
self.input_wav[:] = np.append(self.input_wav[self.block_frame :], indata)
# infer
inp=torch.from_numpy(self.input_wav)
inp=torch.from_numpy(self.input_wav).to(device)
##0
res1=self.resampler(inp)
###55%
rate1=self.block_frame/(self.extra_frame+ self.crossfade_frame+ self.sola_search_frame+ self.block_frame)
rate2=(self.crossfade_frame + self.sola_search_frame + self.block_frame)/(self.extra_frame+ self.crossfade_frame+ self.sola_search_frame+ self.block_frame)
res2=self.rvc.infer(res1,res1[-self.block_frame:].numpy(),rate1,rate2,self.pitch,self.pitchf,self.config.f0method)
res2=self.rvc.infer(res1,res1[-self.block_frame:].cpu().numpy(),rate1,rate2,self.pitch,self.pitchf,self.config.f0method)
self.output_wav_cache[-res2.shape[0]:]=res2
infer_wav = self.output_wav_cache[-self.crossfade_frame - self.sola_search_frame - self.block_frame :].to(device)
infer_wav = self.output_wav_cache[-self.crossfade_frame - self.sola_search_frame - self.block_frame :]
# SOLA algorithm from https://github.com/yxlllc/DDSP-SVC
cor_nom = F.conv1d(
infer_wav[None, None, : self.crossfade_frame + self.sola_search_frame],
Expand Down
12 changes: 12 additions & 0 deletions rvc_for_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(
self.net_g = self.net_g.half()
else:
self.net_g = self.net_g.float()
self.is_half=config.is_half
except:
print(traceback.format_exc())

Expand All @@ -102,6 +103,7 @@ def get_f0_post(self, f0):
def get_f0(self, x, f0_up_key, n_cpu, method="harvest"):
n_cpu = int(n_cpu)
if (method == "crepe"): return self.get_f0_crepe(x, f0_up_key)
if (method == "rmvpe"): return self.get_f0_rmvpe(x, f0_up_key)
if (method == "pm"):
p_len = x.shape[0] // 160
f0 = (
Expand Down Expand Up @@ -181,6 +183,16 @@ def get_f0_crepe(self, x, f0_up_key):
f0 *= pow(2, f0_up_key / 12)
return self.get_f0_post(f0)

def get_f0_rmvpe(self, x, f0_up_key):
if (hasattr(self, "model_rmvpe") == False):
from rmvpe import RMVPE
print("loading rmvpe model")
# self.model_rmvpe = RMVPE("rmvpe.pt", is_half=self.is_half, device=self.device)
self.model_rmvpe = RMVPE("aug2_58000_half.pt", is_half=self.is_half, device=self.device)
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
f0 *= pow(2, f0_up_key / 12)
return self.get_f0_post(f0)

def infer(self, feats: torch.Tensor, indata: np.ndarray, rate1, rate2, cache_pitch, cache_pitchf, f0method) -> np.ndarray:
feats = feats.view(1, -1)
if config.is_half:
Expand Down

0 comments on commit 0f9d2e6

Please sign in to comment.