How to use the nlpaug.augmenter.audio function in nlpaug

To help you get started, we’ve selected a few nlpaug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github makcedward / nlpaug / test / flow / test_flow.py View on Github external
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)
            ])
github makcedward / nlpaug / test / augmenter / audio / test_mask.py View on Github external
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))
github makcedward / nlpaug / test / augmenter / audio / test_loudness.py View on Github external
def test_empty_input(self):
        audio = np.array([])
        aug = naa.LoudnessAug()
        augmented_audio = aug.augment(audio)

        self.assertTrue(np.array_equal(audio, augmented_audio))
github makcedward / nlpaug / test / augmenter / audio / test_noise.py View on Github external
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)
github makcedward / nlpaug / test / augmenter / audio / test_shift.py View on Github external
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))
github makcedward / nlpaug / test / augmenter / audio / test_speed.py View on Github external
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))
github makcedward / nlpaug / test / augmenter / audio / test_noise.py View on Github external
def test_empty_input(self):
        audio = np.array([])
        aug = naa.NoiseAug()
        augmented_audio = aug.augment(audio)

        self.assertTrue(np.array_equal(audio, augmented_audio))