Mercurial > hg > auditok
changeset 216:3708f2eb8a40
Remove deprecated calls in AudioSource
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Sat, 06 Jul 2019 11:17:54 +0100 |
parents | e59b071b03cb |
children | b99eb5767ff6 |
files | auditok/io.py tests/test_AudioDataSource.py tests/test_AudioSource.py |
diffstat | 3 files changed, 64 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/auditok/io.py Fri Jul 05 20:19:34 2019 +0100 +++ b/auditok/io.py Sat Jul 06 11:17:54 2019 +0100 @@ -107,7 +107,9 @@ str 'mix' returns it as is. If it's `left` or `right` returns 0 or 1 respectively. """ - err_message = "'use_channel' parameter must be a non-zero integer or one of " + err_message = ( + "'use_channel' parameter must be a non-zero integer or one of " + ) err_message += "('left', 'right', 'mix'), found: '{}'" if use_channel is None: return 0 @@ -496,7 +498,7 @@ self._buffer += data_buffer def rewind(self): - self.set_position(0) + self.position = 0 @property def position(self): @@ -922,7 +924,9 @@ with open(file, "rb") as fp: data = fp.read() if channels != 1: - use_channel = _normalize_use_channel(use_channel) # TODO: should happen in BufferAudioSource + use_channel = _normalize_use_channel( + use_channel + ) # TODO: should happen in BufferAudioSource data = _extract_selected_channel( data, channels, sample_width, use_channel ) @@ -950,7 +954,9 @@ swidth = fp.getsampwidth() data = fp.readframes(-1) if channels > 1: - use_channel = _normalize_use_channel(use_channel) # TODO: should happen in BufferAudioSource + use_channel = _normalize_use_channel( + use_channel + ) # TODO: should happen in BufferAudioSource data = _extract_selected_channel(data, channels, swidth, use_channel) return BufferAudioSource( data, sampling_rate=srate, sample_width=swidth, channels=1 @@ -979,7 +985,9 @@ segment = open_function(filename) data = segment._data if segment.channels > 1: - use_channel = _normalize_use_channel(use_channel) # TODO: should happen in BufferAudioSource + use_channel = _normalize_use_channel( + use_channel + ) # TODO: should happen in BufferAudioSource data = _extract_selected_channel( data, segment.channels, segment.sample_width, use_channel ) @@ -1053,7 +1061,7 @@ filename, srate, swidth, channels, use_channel, large_file ) - use_channel = kwargs.get("use_channel", kwargs.get("uc")) + use_channel = kwargs.get("use_channel", kwargs.get("uc")) if audio_format in ["wav", "wave"]: return _load_wave(filename, large_file, use_channel) if large_file: @@ -1160,4 +1168,4 @@ ) else: err_message = "cannot write file format {} (file name: {})" - raise AudioIOError(err_message.format(audio_format, file)) \ No newline at end of file + raise AudioIOError(err_message.format(audio_format, file))
--- a/tests/test_AudioDataSource.py Fri Jul 05 20:19:34 2019 +0100 +++ b/tests/test_AudioDataSource.py Sat Jul 06 11:17:54 2019 +0100 @@ -320,7 +320,7 @@ audio_source.open() # Compare all blocks read from OverlapADS to those read - # from an audio source with a manual set_position + # from an audio source with a manual position setting for i, block in enumerate(ads_data): tmp = audio_source.read(block_size) @@ -331,7 +331,7 @@ "Unexpected block (N={0}) read from OverlapADS".format(i), ) - audio_source.set_position((i + 1) * hop_size) + audio_source.position = (i + 1) * hop_size audio_source.close() @@ -367,7 +367,7 @@ audio_source.open() # Compare all blocks read from OverlapADS to those read - # from an audio source with a manual set_position + # from an audio source with a manual position setting for i, block in enumerate(ads_data): tmp = audio_source.read(len(block) // (ads.sw * ads.ch)) self.assertEqual( @@ -375,7 +375,7 @@ len(tmp), "Unexpected block (N={0}) read from OverlapADS".format(i), ) - audio_source.set_position((i + 1) * hop_size) + audio_source.position = (i + 1) * hop_size audio_source.close() @@ -469,7 +469,7 @@ audio_source.open() # Compare all blocks read from OverlapADS to those read - # from an audio source with a manual set_position + # from an audio source with a manual position setting for j in range(i): tmp = audio_source.read(block_size) @@ -479,7 +479,7 @@ tmp, "Unexpected block (N={0}) read from OverlapADS".format(i), ) - audio_source.set_position((j + 1) * hop_size) + audio_source.position = (j + 1) * hop_size ads.close() audio_source.close() @@ -519,7 +519,7 @@ audio_source.open() # Compare all blocks read from OverlapADS to those read - # from an audio source with a manual set_position + # from an audio source with a manual position setting for j in range(i): tmp = audio_source.read(block_size) @@ -529,7 +529,7 @@ tmp, "Unexpected block (N={0}) read from OverlapADS".format(i), ) - audio_source.set_position((j + 1) * hop_size) + audio_source.position = (j + 1) * hop_size ads.close() audio_source.close() @@ -653,7 +653,7 @@ audio_source.open() # Compare all blocks read from OverlapADS to those read - # from an audio source with a manual set_position + # from an audio source with a manual position setting for j in range(i): tmp = audio_source.read(block_size) @@ -667,7 +667,7 @@ block, i ), ) - audio_source.set_position((j + 1) * hop_size) + audio_source.position = (j + 1) * hop_size ads.close() audio_source.close() @@ -994,11 +994,10 @@ tmp, "Unexpected block (N={0}) read from OverlapADS".format(i), ) - audio_source.set_position((j + 1) * hop_size) + audio_source.position = (j + 1) * hop_size ads.close() audio_source.close() if __name__ == "__main__": - # import sys;sys.argv = ['', 'Test.testName'] unittest.main()
--- a/tests/test_AudioSource.py Fri Jul 05 20:19:34 2019 +0100 +++ b/tests/test_AudioSource.py Sat Jul 06 11:17:54 2019 +0100 @@ -386,48 +386,48 @@ with self.assertRaises(IndexError): self.audio_source.position_ms = position_ms - def test_sr10_sw1_ch1_get_time_position_0(self): - tp = self.audio_source.get_time_position() + def test_sr10_sw1_ch1_position_s_0(self): + tp = self.audio_source.position_s self.assertEqual( tp, 0.0, msg="wrong time position, expected: 0.0, found: {0} ".format(tp), ) - def test_sr10_sw1_ch1_get_time_position_1(self): + def test_sr10_sw1_ch1_position_s_1(self): srate = self.audio_source.get_sampling_rate() # read one second self.audio_source.read(srate) - tp = self.audio_source.get_time_position() + tp = self.audio_source.position_s self.assertEqual( tp, 1.0, msg="wrong time position, expected: 1.0, found: {0} ".format(tp), ) - def test_sr10_sw1_ch1_get_time_position_2_5(self): + def test_sr10_sw1_ch1_position_s_2_5(self): # read 2.5 seconds self.audio_source.read(25) - tp = self.audio_source.get_time_position() + tp = self.audio_source.position_s self.assertEqual( tp, 2.5, msg="wrong time position, expected: 2.5, found: {0} ".format(tp), ) - def test_sr10_sw1_ch1_set_time_position_0(self): + def test_sr10_sw1_ch1_position_s_0(self): self.audio_source.read(10) - self.audio_source.set_time_position(0) - tp = self.audio_source.get_time_position() + self.audio_source.position_s = 0 + tp = self.audio_source.position_s self.assertEqual( tp, 0.0, msg="wrong time position, expected: 0.0, found: {0} ".format(tp), ) - def test_sr10_sw1_ch1_set_time_position_1(self): - self.audio_source.set_time_position(1) - tp = self.audio_source.get_time_position() + def test_sr10_sw1_ch1_position_s_1(self): + self.audio_source.position_s = 1 + tp = self.audio_source.position_s self.assertEqual( tp, 1.0, @@ -603,7 +603,7 @@ ), ) - def test_sr16_sw2_ch1_read_set_position_0(self): + def test_sr16_sw2_ch1_read_position_0(self): self.audio_source.read(10) self.audio_source.position = 0 pos = self.audio_source.position @@ -733,7 +733,7 @@ def test_sr16_sw2_ch1_rewind(self): self.audio_source.read(10) self.audio_source.rewind() - tp = self.audio_source.get_position() + tp = self.audio_source.position self.assertEqual( tp, 0, msg="wrong position, expected: 0.0, found: {0} ".format(tp) ) @@ -871,67 +871,67 @@ ), ) - def test_sr11_sw4_ch1_get_position_0(self): - pos = self.audio_source.get_position() + def test_sr11_sw4_ch1_position_0(self): + pos = self.audio_source.position self.assertEqual( pos, 0, msg="wrong position, expected: 0, found: {0} ".format(pos) ) - def test_sr11_sw4_ch1_get_position_5(self): + def test_sr11_sw4_ch1_position_5(self): self.audio_source.read(5) - pos = self.audio_source.get_position() + pos = self.audio_source.position self.assertEqual( pos, 5, msg="wrong position, expected: 5, found: {0} ".format(pos) ) - def test_sr11_sw4_ch1_get_position_9(self): + def test_sr11_sw4_ch1_position_9(self): self.audio_source.read(5) self.audio_source.read(4) - pos = self.audio_source.get_position() + pos = self.audio_source.position self.assertEqual( pos, 9, msg="wrong position, expected: 5, found: {0} ".format(pos) ) - def test_sr11_sw4_ch1_set_position_0(self): + def test_sr11_sw4_ch1_position_0(self): self.audio_source.read(10) - self.audio_source.set_position(0) - pos = self.audio_source.get_position() + self.audio_source.position = 0 + pos = self.audio_source.position self.assertEqual( pos, 0, msg="wrong position, expected: 0, found: {0} ".format(pos) ) - def test_sr11_sw4_ch1_set_position_10(self): - self.audio_source.set_position(10) - pos = self.audio_source.get_position() + def test_sr11_sw4_ch1_position_10(self): + self.audio_source.position = 10 + pos = self.audio_source.position self.assertEqual( pos, 10, msg="wrong position, expected: 10, found: {0} ".format(pos), ) - def test_sr11_sw4_ch1_get_time_position_0(self): - tp = self.audio_source.get_time_position() + def test_sr11_sw4_ch1_position_s_0(self): + tp = self.audio_source.position_s self.assertEqual( tp, 0.0, msg="wrong time position, expected: 0.0, found: {0} ".format(tp), ) - def test_sr11_sw4_ch1_get_time_position_1(self): + def test_sr11_sw4_ch1_position_s_1(self): srate = self.audio_source.get_sampling_rate() # read one second self.audio_source.read(srate) - tp = self.audio_source.get_time_position() + tp = self.audio_source.position_s self.assertEqual( tp, 1.0, msg="wrong time position, expected: 1.0, found: {0} ".format(tp), ) - def test_sr11_sw4_ch1_get_time_position_0_63(self): + def test_sr11_sw4_ch1_position_s_0_63(self): # read 2.5 seconds self.audio_source.read(7) - tp = self.audio_source.get_time_position() + tp = self.audio_source.position_s self.assertAlmostEqual( tp, 0.636363636364, @@ -939,20 +939,20 @@ "found: {0} ".format(tp), ) - def test_sr11_sw4_ch1_set_time_position_0(self): + def test_sr11_sw4_ch1_position_s_0(self): self.audio_source.read(10) - self.audio_source.set_time_position(0) - tp = self.audio_source.get_time_position() + self.audio_source.position_s = 0 + tp = self.audio_source.position_s self.assertEqual( tp, 0.0, msg="wrong time position, expected: 0.0, found: {0} ".format(tp), ) - def test_sr11_sw4_ch1_set_time_position_1(self): + def test_sr11_sw4_ch1_position_s_1(self): - self.audio_source.set_time_position(1) - tp = self.audio_source.get_time_position() + self.audio_source.position_s = 1 + tp = self.audio_source.position_s self.assertEqual( tp, 1.0,