mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-01-19 18:41:52 +00:00
Format code (#274)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
568378761b
commit
af41184320
@@ -2,16 +2,18 @@ import numpy as np, parselmouth, torch, pdb
|
||||
from time import time as ttime
|
||||
import torch.nn.functional as F
|
||||
import scipy.signal as signal
|
||||
import pyworld, os, traceback, faiss,librosa
|
||||
import pyworld, os, traceback, faiss, librosa
|
||||
from scipy import signal
|
||||
from functools import lru_cache
|
||||
|
||||
bh, ah = signal.butter(N=5, Wn=48, btype="high", fs=16000)
|
||||
|
||||
input_audio_path2wav={}
|
||||
input_audio_path2wav = {}
|
||||
|
||||
|
||||
@lru_cache
|
||||
def cache_harvest_f0(input_audio_path,fs,f0max,f0min,frame_period):
|
||||
audio=input_audio_path2wav[input_audio_path]
|
||||
def cache_harvest_f0(input_audio_path, fs, f0max, f0min, frame_period):
|
||||
audio = input_audio_path2wav[input_audio_path]
|
||||
f0, t = pyworld.harvest(
|
||||
audio,
|
||||
fs=fs,
|
||||
@@ -22,6 +24,7 @@ def cache_harvest_f0(input_audio_path,fs,f0max,f0min,frame_period):
|
||||
f0 = pyworld.stonemask(audio, f0, t, fs)
|
||||
return f0
|
||||
|
||||
|
||||
class VC(object):
|
||||
def __init__(self, tgt_sr, config):
|
||||
self.x_pad, self.x_query, self.x_center, self.x_max, self.is_half = (
|
||||
@@ -41,7 +44,16 @@ class VC(object):
|
||||
self.t_max = self.sr * self.x_max # 免查询时长阈值
|
||||
self.device = config.device
|
||||
|
||||
def get_f0(self, input_audio_path,x, p_len, f0_up_key, f0_method,filter_radius, inp_f0=None):
|
||||
def get_f0(
|
||||
self,
|
||||
input_audio_path,
|
||||
x,
|
||||
p_len,
|
||||
f0_up_key,
|
||||
f0_method,
|
||||
filter_radius,
|
||||
inp_f0=None,
|
||||
):
|
||||
global input_audio_path2wav
|
||||
time_step = self.window / self.sr * 1000
|
||||
f0_min = 50
|
||||
@@ -65,9 +77,9 @@ class VC(object):
|
||||
f0, [[pad_size, p_len - len(f0) - pad_size]], mode="constant"
|
||||
)
|
||||
elif f0_method == "harvest":
|
||||
input_audio_path2wav[input_audio_path]=x.astype(np.double)
|
||||
f0=cache_harvest_f0(input_audio_path,self.sr,f0_max,f0_min,10)
|
||||
if(filter_radius>2):
|
||||
input_audio_path2wav[input_audio_path] = x.astype(np.double)
|
||||
f0 = cache_harvest_f0(input_audio_path, self.sr, f0_max, f0_min, 10)
|
||||
if filter_radius > 2:
|
||||
f0 = signal.medfilt(f0, 3)
|
||||
f0 *= pow(2, f0_up_key / 12)
|
||||
# with open("test.txt","w")as f:f.write("\n".join([str(i)for i in f0.tolist()]))
|
||||
@@ -255,7 +267,15 @@ class VC(object):
|
||||
sid = torch.tensor(sid, device=self.device).unsqueeze(0).long()
|
||||
pitch, pitchf = None, None
|
||||
if if_f0 == 1:
|
||||
pitch, pitchf = self.get_f0(input_audio_path,audio_pad, p_len, f0_up_key, f0_method,filter_radius, inp_f0)
|
||||
pitch, pitchf = self.get_f0(
|
||||
input_audio_path,
|
||||
audio_pad,
|
||||
p_len,
|
||||
f0_up_key,
|
||||
f0_method,
|
||||
filter_radius,
|
||||
inp_f0,
|
||||
)
|
||||
pitch = pitch[:p_len]
|
||||
pitchf = pitchf[:p_len]
|
||||
if self.device == "mps":
|
||||
@@ -328,11 +348,11 @@ class VC(object):
|
||||
)[self.t_pad_tgt : -self.t_pad_tgt]
|
||||
)
|
||||
audio_opt = np.concatenate(audio_opt)
|
||||
if(resample_sr>=16000 and tgt_sr!=resample_sr):
|
||||
if resample_sr >= 16000 and tgt_sr != resample_sr:
|
||||
audio_opt = librosa.resample(
|
||||
audio_opt, orig_sr=tgt_sr, target_sr=resample_sr
|
||||
)
|
||||
audio_opt=audio_opt.astype(np.int16)
|
||||
audio_opt = audio_opt.astype(np.int16)
|
||||
del pitch, pitchf, sid
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.empty_cache()
|
||||
|
||||
Reference in New Issue
Block a user