def run(audio_file: str, out_path: str, model_name: str, pretrained_path: str, lowpass_freq: int = 0): wav, sr = librosa.load(audio_file, sr=settings.SAMPLE_RATE) wav = preemphasis(wav) if wav.dtype != np.float32: wav = wav.astype(np.float32) # load model model = __load_model(model_name, pretrained_path) # make tensor wav wav = torch.FloatTensor(wav).unsqueeze(0).cuda() # inference print('Inference ...') with torch.no_grad(): out_wav = model(wav) out_wav = out_wav[0].cpu().numpy() if lowpass_freq: out_wav = lowpass(out_wav, frequency=lowpass_freq) # save wav librosa.output.write_wav(out_path, inv_preemphasis(out_wav).clip(-1., 1.), settings.SAMPLE_RATE) print('Finish !')
def run(*audio_files: [str], out_path: str, model_name: str, pretrained_path: str, lowpass_freq: int = 0, sample_rate: int = 22050): for audio_file in audio_files: print('Loading audio file...') wav, sr = librosa.load(audio_file, sr=sample_rate) wav = preemphasis(wav) if wav.dtype != np.float32: wav = wav.astype(np.float32) # load model model = __load_model(model_name, pretrained_path) # make tensor wav wav = torch.FloatTensor(wav).unsqueeze(0) # inference print('Inference ...') with torch.no_grad(): out_wav = model(wav) out_wav = out_wav[0].cpu().numpy() if lowpass_freq: out_wav = lowpass(out_wav, frequency=lowpass_freq) # save wav librosa.output.write_wav( os.path.join( out_path, os.path.basename(audio_file).rsplit(".", 1)[0] + "_out.wav"), inv_preemphasis(out_wav).clip(-1., 1.), sample_rate) print('Finish !')