Mercurial > hg > auditok
changeset 307:334c8760e80f
Force specifying max_read when reading from microphone in AudioRegion.load
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Fri, 11 Oct 2019 20:58:49 +0100 |
parents | de1afab6a4e5 |
children | bc963239143f |
files | auditok/core.py tests/test_core.py |
diffstat | 2 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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"),