def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) self.noise_path = './tests/test_files/helen.wav'
def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.dafs = [ DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH), DegradedAudioFile(TEST_MONO_WAV_PATH, TMP_PATH), DegradedAudioFile(TEST_MONO_8K_WAV_PATH, TMP_PATH) ]
class TestDegradationMp3: def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) def test_degradation_mp3(self): degradation_mp3 = DegradationMp3() bitrate = '16k' degradation_mp3.set_parameters_values({'bitrate': bitrate}) self.daf.apply_degradation(degradation_mp3) def teardown_class(self): shutil.rmtree(TMP_PATH)
class TestDegradationGain: def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) def test_degradation_gain(self): degradation_gain = DegradationGain() value = -6 degradation_gain.set_parameters_values({'value': value}) sum_before = np.sum(np.abs(self.daf.samples)) self.daf.apply_degradation(degradation_gain) sum_after = np.sum(np.abs(self.daf.samples)) assert (np.abs(sum_after / sum_before - 10**(value/20.0)) < 0.001) def teardown_class(self): shutil.rmtree(TMP_PATH)
class TestDegradationDynamicRangeCompression: def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) def test_degradation_dynamic_range_compression(self): degradation_drcompression = DegradationDynamicRangeCompression() degradation_drcompression.set_parameters_values( {'degree': '3'}) self.daf.apply_degradation(degradation_drcompression) target_y, _ = lr.core.load( './tests/test_files/target_degr_drcompression.wav', sr=None, mono=False) assert np.mean(np.abs(target_y - self.daf.samples)) < 0.001 def teardown_class(self): shutil.rmtree(TMP_PATH)
class TestDegradationTimeStretching: def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) def test_degradation_time_stretching(self): degradation_time_stretching = DegradationTimeStretching() degradation_time_stretching.set_parameters_values( {'time_stretch_factor': '0.9'}) self.daf.apply_degradation(degradation_time_stretching) target_y, _ = lr.core.load( './tests/test_files/target_degr_timestretch.wav', sr=None, mono=False) assert np.mean(np.abs(target_y - self.daf.samples)) < 0.001 def teardown_class(self): shutil.rmtree(TMP_PATH)
class TestDegradationMix: def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) self.noise_path = './tests/test_files/helen.wav' def test_degradation_mix(self): degradation_mix = DegradationMix() degradation_mix.set_parameters_values( {'noise': self.noise_path, 'snr': -12}) self.daf.apply_degradation(degradation_mix) target_y, _ = lr.core.load('./tests/test_files/target_degr_mix.wav', sr=None, mono=False) assert np.mean(np.abs(target_y - self.daf.samples)) < 0.0001 def teardown_class(self): shutil.rmtree(TMP_PATH)
class TestDegradationResample: def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) def test_degradation_resample(self): degradation_resample = DegradationResample() degradation_resample.set_parameters_values( {'sample_rate': 8000}) self.daf.apply_degradation(degradation_resample) target_y, sr = lr.core.load( './tests/test_files/target_degr_resample.wav', sr=None, mono=False) assert self.daf.sample_rate == sr assert np.mean(np.abs(target_y - self.daf.samples)) < 0.001 def teardown_class(self): shutil.rmtree(TMP_PATH)
class TestDegradationEqualization: def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) def test_degradation_equalization(self): degradation_equalization = DegradationEqualization() degradation_equalization.set_parameters_values( {'central_freq': '100', 'bandwidth': '50', 'gain': '-20'}) self.daf.apply_degradation(degradation_equalization) target_y, _ = lr.core.load( './tests/test_files/target_degr_equalize.wav', sr=None, mono=False) assert np.mean(np.abs(target_y - self.daf.samples)) < 0.001 def teardown_class(self): shutil.rmtree(TMP_PATH)
class TestDegradationConvolution: def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) def test_degradation_convolution(self): degradation_convolution = DegradationConvolution() degradation_convolution.set_parameters_values( {'impulse_response': 'impulse_responses/ir_classroom_mono.wav', 'level': '0.7'}) self.daf.apply_degradation(degradation_convolution) target_y, sr = lr.core.load( './tests/test_files/target_degr_convolution.wav', sr=None, mono=False) assert self.daf.sample_rate == sr assert np.mean(np.abs(target_y - self.daf.samples)) < 0.001 def teardown_class(self): shutil.rmtree(TMP_PATH)
class TestDegradationTrim: def setup_class(self): logging.basicConfig(level=logging.DEBUG) if not os.path.isdir(TMP_PATH): os.makedirs(TMP_PATH) self.daf = DegradedAudioFile(TEST_STEREO_WAV_PATH, TMP_PATH) def test_degradation_trim(self): samples, sample_rate = lr.core.load(self.daf.tmp_path, sr=None, mono=False) prev_length = samples.shape[1] degradation_trim = DegradationTrim() trim_seconds = 1 degradation_trim.set_parameters_values({'start_time': trim_seconds}) self.daf.apply_degradation(degradation_trim) samples, sample_rate = lr.core.load(self.daf.tmp_path, sr=None, mono=False) after_length = samples.shape[1] assert after_length == prev_length - int(sample_rate * trim_seconds) def teardown_class(self): shutil.rmtree(TMP_PATH)