Upload noise_removal.py
Browse files- utils/noise_removal.py +9 -4
utils/noise_removal.py
CHANGED
@@ -1,8 +1,13 @@
|
|
1 |
from speechbrain.pretrained import SpectralMaskEnhancement
|
2 |
import torchaudio
|
|
|
|
|
3 |
|
4 |
-
model = SpectralMaskEnhancement.from_hparams(
|
5 |
-
|
|
|
6 |
def remove_noise(input_path, output_path):
|
7 |
-
|
8 |
-
|
|
|
|
|
|
1 |
from speechbrain.pretrained import SpectralMaskEnhancement
|
2 |
import torchaudio
|
3 |
+
import os
|
4 |
+
import torch
|
5 |
|
6 |
+
model = SpectralMaskEnhancement.from_hparams(
|
7 |
+
source="speechbrain/metricgan-plus-voicebank", savedir="tmp/denoiser"
|
8 |
+
)
|
9 |
def remove_noise(input_path, output_path):
|
10 |
+
noisy_audio, sr = torchaudio.load(input_path)
|
11 |
+
lengths = torch.tensor([noisy_audio.shape[1]]) / noisy_audio.shape[1]
|
12 |
+
denoised = model.enhance_batch(noisy_audio, lengths)
|
13 |
+
torchaudio.save(output_path, denoised.cpu(), sr)
|