Spaces:
Build error
Build error
Update src/vc_infer_pipeline.py
Browse files123456789101112131422 unmodified lines3738394041424344454647484950403 unmodified lines45445545645745845946046146246346446528 unmodified lines494495496497498499500501from functools import lru_cacheimport numpy as np, parselmouth, torch, pdb, sys, osfrom time import time as ttimeimport torch.nn.functional as Fimport torchcrepefrom scipy import signalfrom torch import Tensorimport pyworld, os, faiss, librosa, torchcrepeimport randomimport gcimport reBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))now_dir = os.path.join(BASE_DIR, 'src')22 unmodified linesdef change_rms(data1, sr1, data2, sr2, rate):rms1 = librosa.feature.rms(y=data1, frame_length=sr1 // 2 * 2, hop_length=sr1 // 2)rms2 = librosa.feature.rms(y=data2, frame_length=sr2 // 2 * 2, hop_length=sr2 // 2)rms1 = torch.from_numpy(rms1)rms1 = F.interpolate(rms1.unsqueeze(0), size=data2.shape[0], mode="linear").squeeze()rms2 = torch.from_numpy(rms2)rms2 = F.interpolate(rms2.unsqueeze(0), size=data2.shape[0], mode="linear").squeeze()rms2 = torch.max(rms2, torch.zeros_like(rms2) + 1e-6)data2 *= (torch.pow(rms1, torch.tensor(1 - rate))* torch.pow(rms2, torch.tensor(rate - 1))).numpy()return data2403 unmodified linescrepe_hop_length,f0_file=None,):if file_index != "" and os.path.exists(file_index) == True and index_rate != 0:try:index = faiss.read_index(file_index)big_npy = index.reconstruct_n(0, index.ntotal)except Exception as error:print(error)index = big_npy = Noneelse:index = big_npy = None28 unmodified linesfor line in lines:inp_f0.append([float(i) for i in line.split(",")])inp_f0 = np.array(inp_f0, dtype="float32")except Exception as error:print(error)sid = torch.tensor(sid, device=self.device).unsqueeze(0).long()pitch, pitchf = None, Noneif if_f0 == 1:12345678910111222 unmodified lines3536373839404142434445464748495051525354555657403 unmodified lines46146246346446546646746846947047147247347447547628 unmodified lines505506507508509510511512import numpy as np, parselmouth, torch, pdb, sys, osfrom time import time as ttimeimport torch.nn.functional as Fimport torchcrepefrom torch import Tensorimport scipy.signal as signalimport pyworld, os, traceback, faiss, librosa, torchcrepefrom scipy import signalfrom functools import lru_cacheBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))now_dir = os.path.join(BASE_DIR, 'src')22 unmodified linesdef change_rms(data1, sr1, data2, sr2, rate):rms1 = librosa.feature.rms(y=data1, frame_length=sr1 // 2 * 2, hop_length=sr1 // 2)rms2 = librosa.feature.rms(y=data2, frame_length=sr2 // 2 * 2, hop_length=sr2 // 2)rms1 = torch.from_numpy(rms1)rms1 = F.interpolate(rms1.unsqueeze(0), size=data2.shape[0], mode="linear").squeeze()rms2 = torch.from_numpy(rms2)rms2 = F.interpolate(rms2.unsqueeze(0), size=data2.shape[0], mode="linear").squeeze()rms2 = torch.max(rms2, torch.zeros_like(rms2) + 1e-6)data2 *= (torch.pow(rms1, torch.tensor(1 - rate))* torch.pow(rms2, torch.tensor(rate - 1))).numpy()return data2403 unmodified linescrepe_hop_length,f0_file=None,):if (file_index != ""and os.path.exists(file_index) == Trueand index_rate != 0):try:index = faiss.read_index(file_index)big_npy = index.reconstruct_n(0, index.ntotal)except:traceback.print_exc()index = big_npy = Noneelse:index = big_npy = None28 unmodified linesfor line in lines:inp_f0.append([float(i) for i in line.split(",")])inp_f0 = np.array(inp_f0, dtype="float32")except:traceback.print_exc()sid = torch.tensor(sid, device=self.device).unsqueeze(0).long()pitch, pitchf = None, Noneif if_f0 == 1:
src/vc_infer_pipeline.py+26-15