def gen_augmented(original, sample_rate): # list of augmentors available from the nlpaug library augment_list = [ #naa.CropAug(sampling_rate=sample_rate) naa.NoiseAug(), naa.SpeedAug(), naa.LoudnessAug(factor=(0.5, 2)), naa.VtlpAug(sampling_rate=sample_rate, zone=(0.0, 1.0)), naa.PitchAug(sampling_rate=sample_rate, factor=(-1, 3)) ] # sample augmentation randomly aug_idx = random.randint(0, len(augment_list) - 1) augmented_data = augment_list[aug_idx].augment(original) return augmented_data
def test_zone(self): zone = (0, 1) coverage = 1. for _ in range(10): aug = naa.VtlpAug(sampling_rate=self.sampling_rate, zone=zone, coverage=coverage) aug.model.stateless = False aug.augment(self.audio) self.assertGreater( len(self.audio[aug.model.start_pos:aug.model.end_pos]), len(aug.model.aug_data))
def test_coverage_and_zone(self): params = [ ((0.3, 0.7), 1), ((0, 1), 1) ] for zone, coverage in params: augs = [ naa.LoudnessAug(zone=zone, coverage=coverage, stateless=False), naa.MaskAug(zone=zone, coverage=coverage, stateless=False), naa.NoiseAug(zone=zone, coverage=coverage, stateless=False), naa.PitchAug(zone=zone, coverage=coverage, stateless=False, sampling_rate=self.sampling_rate), naa.SpeedAug(zone=zone, coverage=coverage, stateless=False), naa.VtlpAug(zone=zone, coverage=coverage, stateless=False, sampling_rate=self.sampling_rate), naa.NormalizeAug(zone=zone, coverage=coverage, stateless=False), naa.PolarityInverseAug(zone=zone, coverage=coverage, stateless=False) ] for aug in augs: aug_data = aug.augment(self.audio) self.assertTrue(len(aug_data[aug.start_pos:aug.end_pos]), int(len(self.audio) * (zone[1] - zone[0]) * coverage))
def test_substitute(self): for _ in range(10): aug = naa.VtlpAug(sampling_rate=self.sampling_rate, stateless=False) augmented_audio = aug.augment(self.audio) self.assertGreater(len(self.audio), len(augmented_audio))
import nlpaug.augmenter.audio as naa import librosa import glob from tqdm import tqdm import os wlist=glob.glob(r'../IEMOCAP/*.wav') targetDir='../IEMOCAP/' aug = naa.VtlpAug(16000, zone=(0.0, 1.0), coverage=1, duration=None, fhi=4800, factor=(0.8, 1.2)) for w in tqdm(wlist): for i in range(7): wav,_=librosa.load(w,16000) wavAug=aug.augment(wav) wavName=os.path.basename(w) librosa.output.write_wav(targetDir+wavName+'.'+str(i+1),wavAug,16000)
def vtlp(data, sampling_rate): aug = naa.VtlpAug(sampling_rate=sampling_rate) return aug.augment(data)
def add_vltk(data, sr): aug = naa.VtlpAug(sampling_rate=sr) return aug.augment(data)