Commit 295d9fa5 authored by Gaël Le Lan's avatar Gaël Le Lan
Browse files

scipy convolution for reverb

parent 1b6ebce4
......@@ -28,6 +28,7 @@ Copyright 2014-2021 Anthony Larcher
import collections
import math
import numpy
from scipy import signal
import pandas
import random
import soundfile
......@@ -478,12 +479,7 @@ def data_augmentation(speech, sample_rate, transform_dict, transform_number, noi
rir_fn = transform_dict["add_reverb"]["data_path"] + "/" + rir_nfo + ".wav"
rir, rir_fs = torchaudio.load(rir_fn)
#rir = rir[rir_nfo[1], :] #keep selected channel
delta = speech.size(-1) - rir.size(-1)
kernel = torch.nn.functional.pad(rir, (0, delta))
#speech_ = torch.nn.functional.pad(speech, (kernel.shape[1], 0))
# Multiply in frequency domain to convolve in time domain
result = torch.fft.rfft(speech) * torch.fft.rfft(kernel)
speech = torch.fft.irfft(result, n=speech.size(-1))
speech = torch.tensor(signal.convolve(speech, rir, mode='full')[:, :speech.shape[1]])
if "add_noise" in augmentations:
# Pick a noise type
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment