def test_serialize_deserialize_transform_volume(audio): volume_orig = Volume(factor=0.5) data_volume = volume_orig.to_dict() volume = AudioTransform.from_dict(data_volume) perturbed_volume = volume(audio, SAMPLING_RATE) assert perturbed_volume.shape == audio.shape assert_array_almost_equal(perturbed_volume, audio * 0.5)
def test_deserialize_transform_volume(audio): volume = AudioTransform.from_dict({ "name": "Volume", "kwargs": { "factor": 0.5 } }) perturbed_volume = volume(audio, SAMPLING_RATE) assert perturbed_volume.shape == audio.shape assert_array_almost_equal(perturbed_volume, audio * 0.5)
def test_volume_does_not_change_num_samples(audio): augment_fn = SoxEffectTransform(effects=volume(SAMPLING_RATE)) for _ in range(10): augmented_audio = augment_fn(audio, sampling_rate=SAMPLING_RATE) assert augmented_audio.shape == audio.shape assert augmented_audio != audio
def test_volume(audio_volume, scale): volume = Volume(factor=scale) audio_perturbed = volume(audio_volume, SAMPLING_RATE) assert audio_perturbed.shape == audio_volume.shape assert_array_almost_equal(audio_perturbed, scale * audio_volume)