def test_reverb_with_multi_channel_impulse_response(audio, multi_channel_rir, rir_channels, expected_num_channels): if expected_num_channels is not None: augment_fn = ReverbWithImpulseResponse(rir=multi_channel_rir, rir_channels=rir_channels) for _ in range(10): augmented_audio = augment_fn(audio, sampling_rate=SAMPLING_RATE) assert augmented_audio.shape == (expected_num_channels, 16000) else: with pytest.raises(AssertionError): augment_fn = ReverbWithImpulseResponse(rir=multi_channel_rir, rir_channels=rir_channels)
def test_reverb_normalize_output(audio, rir, normalize_output, early_only): augment_fn = ReverbWithImpulseResponse( rir=rir, normalize_output=normalize_output, early_only=early_only ) orig_energy = np.sum(np.abs(audio) ** 2) / audio.shape[1] for _ in range(10): augmented_audio = augment_fn(audio, sampling_rate=SAMPLING_RATE) rvb_energy = np.sum(np.abs(augmented_audio) ** 2) / augmented_audio.shape[1] if normalize_output: assert_array_almost_equal(rvb_energy, orig_energy)
def test_reverb_does_not_change_num_samples(audio, rir, early_only): augment_fn = ReverbWithImpulseResponse(rir=rir, early_only=early_only) for _ in range(10): augmented_audio = augment_fn(audio, sampling_rate=SAMPLING_RATE) assert augmented_audio.shape == (1, 16000)
def test_serialize_deserialize_transform_reverb(audio, rir, recording_to_dict): rir = rir.to_dict() if recording_to_dict else rir reverb_orig = ReverbWithImpulseResponse(rir=rir) data_reverb = reverb_orig.to_dict() reverb = ReverbWithImpulseResponse.from_dict(data_reverb) assert reverb_orig == reverb