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_multi_thread(self):
audio, sampling_rate = AudioLoader.load_audio(self.sample_wav_file)
n = 3
augs = [
naa.CropAug(sampling_rate=sampling_rate),
naa.PitchAug(sampling_rate=sampling_rate)
]
for num_thread in [1, 3]:
for aug in augs:
augmented_data = aug.augment(audio, n=n, num_thread=num_thread)
self.assertEqual(len(augmented_data), n)
def test_empty_input(self):
audio = np.array([])
aug = naa.CropAug(sampling_rate=self.sampling_rate)
augmented_audio = aug.augment(audio)
self.assertTrue(np.array_equal(audio, augmented_audio))
def test_substitute(self):
aug = naa.CropAug(sampling_rate=self.sampling_rate)
augmented_audio = aug.augment(self.audio)
self.assertNotEqual(len(self.audio), len(augmented_audio))
os.path.dirname(__file__), '..', '..', '.env'))
load_dotenv(env_config_path)
# https://freewavesamples.com/yamaha-v50-rock-beat-120-bpm
cls.sample_wav_file = os.path.join(
os.environ.get("TEST_DIR"), 'res', 'audio', 'Yamaha-V50-Rock-Beat-120bpm.wav'
)
cls.audio, cls.sampling_rate = AudioLoader.load_audio(cls.sample_wav_file)
cls.textual_augs = [
nac.RandomCharAug(),
naw.ContextualWordEmbsAug(),
nas.ContextualWordEmbsForSentenceAug()
]
cls.audio_augs = [
naa.CropAug(sampling_rate=cls.sampling_rate),
naa.SpeedAug(),
]
def test_coverage(self):
aug = naa.CropAug(sampling_rate=self.sampling_rate, coverage=0.1)
augmented_data = aug.augment(self.audio)
audio_size = len(self.audio)
augmented_size = len(augmented_data)
expected_crop_size = len(self.audio) * (aug.model.zone[1] - aug.model.zone[0]) * 0.1
self.assertTrue(-1 <= audio_size - augmented_size - expected_crop_size <= 1)
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)
])
]
for flow in flows:
augmented_audios = flow.augment(audio, n=3)
self.assertGreater(len(augmented_audios), 1)
for augmented_audio in augmented_audios:
self.assertFalse(np.array_equal(audio, augmented_audio))
self.assertLess(0, len(flows))
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