github地址
降噪代码
import torch
import torchaudio
from denoiser import pretrained
from denoiser.dsp import convert_audio
import soundfile
model = pretrained.dns64().cpu() # .cuda()
# 加载原文件
wav, sr = torchaudio.load('../../dataset/alex_noisy.mp3')
# wav, sr = torchaudio.load('after_5.wav')
# 处理
wav = convert_audio(wav.cpu(), sr, model.sample_rate, model.chin) # .cuda()
with torch.no_grad():
denoised = model(wav[None])[0]
# 保存
soundfile.write('after_alex_noisy.wav', denoised.data.cpu().numpy().T, sr) # numpy格式数据保存音频
torchaudio.save('after_alex_noisy.wav', denoised, sr) # tensor格式数据保存音频