Add noise first to audio_aug

This commit is contained in:
James Betker 2021-08-05 23:22:44 -06:00
parent d6007c6de1
commit 908ef5495f
2 changed files with 9 additions and 8 deletions

View File

@ -45,9 +45,9 @@ class WavAugmentor:
]
vol_effect = random.choice(volume_effects)
effects = [speed_effect, band_effect, vol_effect]
out, sr = torchaudio.sox_effects.apply_effects_tensor(wav, sample_rate, effects)
# Add a variable amount of noise
out = out + torch.rand_like(out) * random.random() * .05
out = wav + torch.rand_like(wav) * random.random() * .05
out, sr = torchaudio.sox_effects.apply_effects_tensor(out, sample_rate, effects)
return out

View File

@ -63,8 +63,8 @@ class WavfileDataset(torch.utils.data.Dataset):
clip2 = self.augmentor.augment(clip2, self.sampling_rate)
return {
'clip1': clip1,
'clip2': clip2,
'clip1': clip1[0, :].unsqueeze(0),
'clip2': clip2[0, :].unsqueeze(0),
'path': filename,
}
@ -83,10 +83,11 @@ if __name__ == '__main__':
}
from data import create_dataset, create_dataloader, util
ds, c = create_dataset(params, return_collate=True)
ds = create_dataset(params, return_collate=True)
dl = create_dataloader(ds, params, collate_fn=c)
i = 0
for b in tqdm(dl):
torchaudio.save(f'{i}_clip1.wav', b['clip1'], ds.sampling_rate)
torchaudio.save(f'{i}_clip2.wav', b['clip2'], ds.sampling_rate)
i += 1
for b_ in range(16):
torchaudio.save(f'{i}_clip1_{b_}.wav', b['clip1'][b_], ds.sampling_rate)
torchaudio.save(f'{i}_clip2_{b_}.wav', b['clip2'][b_], ds.sampling_rate)
i += 1