# HG changeset patch # User Amine Sehili # Date 1570823929 -3600 # Node ID 334c8760e80fa4d9bf7b30d5f0e0ef379b6ba554 # Parent de1afab6a4e51815981d444dacfb1d3febc998cb Force specifying max_read when reading from microphone in AudioRegion.load diff -r de1afab6a4e5 -r 334c8760e80f auditok/core.py --- a/auditok/core.py Fri Oct 11 20:43:07 2019 +0100 +++ b/auditok/core.py Fri Oct 11 20:58:49 2019 +0100 @@ -37,7 +37,6 @@ **kwargs ): """Splits audio data and returns a generator of `AudioRegion`s - TODO: implement max_trailing_silence :Parameters: @@ -181,7 +180,6 @@ ) ) - # print(min_length, max_length, max_continuous_silence) tokenizer = StreamTokenizer( validator, min_length, max_length, max_continuous_silence, mode=mode ) @@ -395,8 +393,12 @@ self._meta = _AudioRegionMetadata(new_meta) @classmethod - def load(cls, file, skip=0, max_read=None, **kwargs): - audio_source = get_audio_source(file, **kwargs) + def load(cls, input, skip=0, max_read=None, **kwargs): + if input is None and max_read is None: + raise ValueError( + "'max_read' should not be None when reading from microphone" + ) + audio_source = get_audio_source(input, **kwargs) audio_source.open() if skip is not None and skip > 0: skip_samples = int(skip * audio_source.sampling_rate) diff -r de1afab6a4e5 -r 334c8760e80f tests/test_core.py --- a/tests/test_core.py Fri Oct 11 20:43:07 2019 +0100 +++ b/tests/test_core.py Fri Oct 11 20:58:49 2019 +0100 @@ -1079,6 +1079,14 @@ str(audio_param_err.exception), ) + def test_load_exception(self): + with self.assertRaises(ValueError) as val_err: + AudioRegion.load(None, sr=16000, sw=2, ch=1) + self.assertEqual( + "'max_read' should not be None when reading from microphone", + str(val_err.exception), + ) + @genty_dataset( simple=("output.wav", 1.230, "output.wav"), start=("output_{meta.start:g}.wav", 1.230, "output_1.23.wav"),