MCPcopy Create free account
hub / github.com/espnet/espnet / _apply_data_augmentation

Method _apply_data_augmentation

espnet2/train/preprocessor.py:2181–2217  ·  view source on GitHub ↗
(self, speech)

Source from the content-addressed store, hash-verified

2179 return noise
2180
2181 def _apply_data_augmentation(self, speech):
2182 # speech: (Nmic, Time)
2183 if speech.ndim == 1:
2184 speech = speech[None, :]
2185 else:
2186 speech = speech.T
2187
2188 if self.rirs is not None and self.rir_apply_prob >= np.random.random():
2189 speech, _ = self._convolve_rir(speech, self.rirs)
2190
2191 if self.noises and self.noise_apply_prob >= np.random.random():
2192 idx = random.choices(
2193 range(len(self.noises)), weights=self.noise_probs, k=1
2194 )[0]
2195 low, high = self.noise_num_to_mix[idx]
2196 if low == high:
2197 num_to_mix = low
2198 else:
2199 num_to_mix = np.random.randint(low, high + 1)
2200
2201 # add eps of 1e-4 to avoid negative value before log
2202 speech_db = 10 * np.log10(np.mean(speech**2) + 1e-4)
2203 noiselist = []
2204 for _ in range(num_to_mix):
2205 noise = self._load_noise(
2206 speech, # original speech
2207 speech_db, # db of speech
2208 self.noises[idx], # a list of a type of noise
2209 self.noise_db_ranges[idx][0], # min db
2210 self.noise_db_ranges[idx][1], # max db
2211 )
2212 noiselist.append(noise)
2213 noise = np.sum(np.concatenate(noiselist, axis=0), axis=0, keepdims=True)
2214 speech = speech + noise
2215
2216 speech = np.squeeze(speech, axis=0)
2217 return speech
2218
2219 def _text_process(
2220 self, data: Dict[str, Union[str, np.ndarray]]

Callers 1

_speech_processMethod · 0.95

Calls 4

_convolve_rirMethod · 0.95
_load_noiseMethod · 0.95
choicesMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected