Commit f7bde72b authored by Anthony Larcher's avatar Anthony Larcher
Browse files

New IdMap.split

modif in _add_noise
parent 24d726cf
......@@ -363,3 +363,24 @@ class IdMap:
raise Exception('Wrong format of IdMap')
return idmap
def split(self, N):
Split an IdMap object into N IdMap of same size (if possible)
:param N: the number of IdMap to generate
:return: a list of IdMap
session_nb = self.leftids.shape[0]
sub_indices = numpy.array_split(numpy.arange(session_nb), N)
im_list = []
for ii in range(N):
im_list[ii].leftids = self.leftids[sub_indices[ii]]
im_list[ii].rightids = self.rightids[sub_indices[ii]]
im_list[ii].start = self.startids[sub_indices[ii]]
im_list[ii].stop = self.stop[sub_indices[ii]]
assert im_list[ii].validate(), "Error: wrong IdMap format"
return im_list
\ No newline at end of file
......@@ -1438,9 +1438,10 @@ def _add_noise(signal, noise_file_name, snr, sample_rate):
# Open noise file
noise, fs_noise = read_audio(noise_file_name, sample_rate)
print("Noise.shape = {}".format(noise.shape))
print("signal.shape = {}".format(signal.shape))
if isinstance(noise_file_name, numpy.ndarray):
noise = noise_file_name
noise, fs_noise = read_audio(noise_file_name, sample_rate)
# Generate random section of masker
if len(noise) < len(signal):
......@@ -1551,7 +1552,10 @@ def _add_reverb(signal, reverb_file_name, sample_rate, reverb_level=-26.0, ):
'''Adds reverb (convolutive noise) to a speech signal.
The output speech level is normalized to asl_level.
reverb, _ = read_audio(reverb_file_name, sample_rate)
if isinstance(reverb_file_name, numpy.ndarray):
reverb = reverb_file_name
reverb, _ = read_audio(reverb_file_name, sample_rate)
y = lfilter(reverb, 1, signal)
y = y/10**(asl_meter(y, sample_rate)/20) * 10**(reverb_level/20)
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