How to use the nlpaug.augmenter.audio.NoiseAug 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 / augmenter / audio / test_noise.py View on Github external
def test_color_noise(self):
        colors = naa.NoiseAug().model.COLOR_NOISES

        for color in colors:
            aug = naa.NoiseAug(color=color)
            augmented_audio = aug.augment(self.audio)

            self.assertFalse(np.array_equal(self.audio, augmented_audio))
            self.assertTrue(len(self.audio), len(augmented_audio))
            self.assertTrue(self.sampling_rate > 0)
github makcedward / nlpaug / test / flow / test_sequential.py View on Github external
def test_audio(self):
        # https://freewavesamples.com/yamaha-v50-rock-beat-120-bpm
        sample_wav_file = os.path.join(
            os.environ.get("TEST_DIR"), 'res', 'audio', 'Yamaha-V50-Rock-Beat-120bpm.wav'
        )

        audio, sampling_rate = AudioLoader.load_audio(sample_wav_file)

        flow = naf.Sequential([
            naa.NoiseAug(),
            naa.PitchAug(sampling_rate=sampling_rate, factor=(0.2, 1.5)),
            naa.ShiftAug(sampling_rate=sampling_rate, duration=2),
            naa.SpeedAug(factor=(1.5, 3))
        ])

        augmented_audio = flow.augment(audio)

        self.assertFalse(np.array_equal(audio, augmented_audio))
        self.assertTrue(len(audio), len(augmented_audio))
github makcedward / nlpaug / test / augmenter / audio / test_noise.py View on Github external
def test_zone(self):
        zone = (0, 1)
        coverage = 1.
        expected_aug_data_size = int(len(self.audio) * (zone[1] - zone[0]) * coverage)

        # background noise
        aug = naa.NoiseAug(zone=zone, noises=[self.noise], coverage=coverage)
        aug.model.stateless = False
        aug.augment(self.audio)

        self.assertTrue(-1 <= len(aug.model.aug_data) - expected_aug_data_size <= 1)

        # colored noise
        aug = naa.NoiseAug(zone=zone, color='pink', coverage=coverage)
        aug.model.stateless = False
        aug.augment(self.audio)

        self.assertTrue(-1 <= len(aug.model.aug_data) - expected_aug_data_size <= 1)
github makcedward / nlpaug / test / augmenter / audio / test_noise.py View on Github external
def test_coverage(self):
        zone = (0.3, 0.7)
        coverage = 0.1
        expected_aug_data_size = int(len(self.audio) * (zone[1] - zone[0]) * coverage)

        # background noise
        aug = naa.NoiseAug(zone=zone, noises=[self.noise], coverage=coverage)
        aug.model.stateless = False
        aug.augment(self.audio)

        self.assertTrue(-1 <= len(aug.model.aug_data) - expected_aug_data_size <= 1)

        # colored noise
        aug = naa.NoiseAug(zone=zone, color='pink', coverage=coverage)
        aug.model.stateless = False
        aug.augment(self.audio)

        self.assertTrue(-1 <= len(aug.model.aug_data) - expected_aug_data_size <= 1)
github makcedward / nlpaug / test / augmenter / audio / test_noise.py View on Github external
def test_coverage(self):
        zone = (0.3, 0.7)
        coverage = 0.1
        expected_aug_data_size = int(len(self.audio) * (zone[1] - zone[0]) * coverage)

        # background noise
        aug = naa.NoiseAug(zone=zone, noises=[self.noise], coverage=coverage)
        aug.model.stateless = False
        aug.augment(self.audio)

        self.assertTrue(-1 <= len(aug.model.aug_data) - expected_aug_data_size <= 1)

        # colored noise
        aug = naa.NoiseAug(zone=zone, color='pink', coverage=coverage)
        aug.model.stateless = False
        aug.augment(self.audio)

        self.assertTrue(-1 <= len(aug.model.aug_data) - expected_aug_data_size <= 1)
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_noise.py View on Github external
def test_zone(self):
        zone = (0, 1)
        coverage = 1.
        expected_aug_data_size = int(len(self.audio) * (zone[1] - zone[0]) * coverage)

        # background noise
        aug = naa.NoiseAug(zone=zone, noises=[self.noise], coverage=coverage)
        aug.model.stateless = False
        aug.augment(self.audio)

        self.assertTrue(-1 <= len(aug.model.aug_data) - expected_aug_data_size <= 1)

        # colored noise
        aug = naa.NoiseAug(zone=zone, color='pink', coverage=coverage)
        aug.model.stateless = False
        aug.augment(self.audio)

        self.assertTrue(-1 <= len(aug.model.aug_data) - expected_aug_data_size <= 1)
github dessa-public / fake-voice-detection / code / utils.py View on Github external
def process_audio_files_with_aug(filename, dirpath):
    sr = 16000
    audio_array, sample_rate = librosa.load(os.path.join(dirpath, 'flac', filename), sr=sr)
    aug_crop = naa.CropAug(sampling_rate=sr)
    audio_array_crop = aug_crop.augment(audio_array)
    aug_loud = naa.LoudnessAug(loudness_factor=(2, 5))
    audio_array_loud = aug_loud.augment(audio_array)
    aug_noise = naa.NoiseAug(noise_factor=0.03)
    audio_array_noise = aug_noise.augment(audio_array)

    audio_array_list= [audio_array,audio_array_crop,audio_array_loud,
                       audio_array_noise ]

    out_list = convert_audio_to_processed_list(audio_array_list, filename, dirpath)

    return out_list