Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_n_output_audio(self):
audio, sampling_rate = AudioLoader.load_audio(self.sample_wav_file)
flows = [
naf.Sequential([
naa.CropAug(sampling_rate=sampling_rate),
naa.LoudnessAug()
]),
naf.Sometimes([
naa.CropAug(sampling_rate=sampling_rate),
naa.LoudnessAug()
], pipeline_p=0.9),
naf.Sequential([
naf.Sequential([
naa.CropAug(sampling_rate=sampling_rate),
naa.LoudnessAug()
]),
naf.Sometimes([
naa.CropAug(sampling_rate=sampling_rate),
naa.LoudnessAug()
], pipeline_p=0.9)
])
def test_coverage(self):
zone = (0.3, 0.7)
coverage = 0.1
aug = naa.MaskAug(sampling_rate=self.sampling_rate, zone=zone, coverage=coverage, mask_with_noise=False)
aug.model.stateless = False
augmented_audio = aug.augment(self.audio)
reconstruct_augmented_audio = np.concatenate(
(self.audio[:aug.model.start_pos], aug.model.aug_data, self.audio[aug.model.end_pos:]), axis=0)
self.assertTrue(np.array_equal(augmented_audio, reconstruct_augmented_audio))
self.assertTrue(len(aug.model.aug_data), int(len(self.audio) * (zone[1] - zone[0]) * coverage))
def test_empty_input(self):
audio = np.array([])
aug = naa.LoudnessAug()
augmented_audio = aug.augment(audio)
self.assertTrue(np.array_equal(audio, augmented_audio))
def test_background_noise(self):
# noise > audio
aug = naa.NoiseAug(noises=[self.noise])
augmented_audio = aug.augment(self.audio)
self.assertTrue(augmented_audio is not None)
# audio > noise
aug = naa.NoiseAug(noises=[self.audio])
augmented_audio = aug.augment(self.noise)
self.assertTrue(augmented_audio is not None)
def test_substitute(self):
audio, sampling_rate = AudioLoader.load_audio(self.sample_wav_file)
aug = naa.ShiftAug(sampling_rate, duration=0.5)
augmented_audio = aug.augment(audio)
self.assertFalse(np.array_equal(audio, augmented_audio))
self.assertTrue(len(audio), len(augmented_audio))
def test_substitute(self):
for _ in range(10):
aug = naa.SpeedAug()
aug.model.stateless = False
augmented_audio = aug.augment(self.audio)
if aug.model.aug_factor < 1:
self.assertGreater(len(augmented_audio), len(self.audio))
else:
self.assertLess(len(augmented_audio), len(self.audio))
def test_empty_input(self):
audio = np.array([])
aug = naa.NoiseAug()
augmented_audio = aug.augment(audio)
self.assertTrue(np.array_equal(audio, augmented_audio))