Mercurial > hg > auditok
diff auditok/io.py @ 170:684392cc5019
Add get_audio_source
author | Amine Sehili <amine.sehili@gmail.com> |
---|---|
date | Thu, 07 Mar 2019 21:28:23 +0100 |
parents | 1fa7fa2857d4 |
children | 00790b3d5aa2 |
line wrap: on
line diff
--- a/auditok/io.py Thu Mar 07 21:00:50 2019 +0100 +++ b/auditok/io.py Thu Mar 07 21:28:23 2019 +0100 @@ -782,6 +782,27 @@ audio_source.get_channels(), ) +def get_audio_source(input=None, **kwargs): + + # read data from standard input + if input == "-": + return StdinAudioSource(**kwargs) + + # create AudioSource from raw data + if isinstance(input, bytes): + return BufferAudioSource(input, **kwargs) + + # read data from a file + if input is not None: + return from_file(filename=input, + audio_format=kwargs.get('audio_format'), + large_file=kwargs.get('large_file', False), + **kwargs) + + # read data from microphone via pyaudio + else: + return PyAudioSource(**kwargs) + def _load_raw( file,