Mercurial > hg > auditok
changeset 79:d4eec2afbe01
Select pyaudio audio device from command line
* Additional cmdline argument for pyaudio
* Update command line args and README for PyAudio
* README typo
author | Mathieu Durand <mathieu.durand@ingeno.ca> |
---|---|
date | Thu, 01 Nov 2018 01:51:44 -0400 |
parents | d942a78cb816 |
children | b3dffec14dfb |
files | README.md auditok/cmdline.py auditok/io.py |
diffstat | 3 files changed, 16 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/README.md Sat Oct 06 12:02:01 2018 +0200 +++ b/README.md Thu Nov 01 01:51:44 2018 -0400 @@ -86,6 +86,13 @@ rec -q -t raw -r 16000 -c 1 -b 16 -e signed - | auditok -i - +### PyAudio + +When capturing input with PyAudio, you may need to adjust the device index with -I if multiple input devices are available. Use `lsusb -t` to get the list of usb devices, or use `arecord -l` if you're using a non-usb input device. If you don't know what index to use, just try `0`, `1`, `2` and so on, outputting the audio using `-E` (echo) until you hear the sound. + +You may also get an error `[Errno -9981] Input overflowed` from PyAudio. If that's the case, you need a bigger frame buffer. +Use `-F` with 2048 or 4096 (the default is 1024). + ### Play back detections auditok -E
--- a/auditok/cmdline.py Sat Oct 06 12:02:01 2018 +0200 +++ b/auditok/cmdline.py Thu Nov 01 01:51:44 2018 -0400 @@ -576,6 +576,8 @@ group.add_option("-r", "--rate", dest="sampling_rate", help="Sampling rate of audio data [default: %default]", type=int, default=16000, metavar="INT") group.add_option("-c", "--channels", dest="channels", help="Number of channels of audio data [default: %default]", type=int, default=1, metavar="INT") group.add_option("-w", "--width", dest="sample_width", help="Number of bytes per audio sample [default: %default]", type=int, default=2, metavar="INT") + group.add_option("-I", "--input-device-index", dest="input_device_index", help="Audio device index [default: %default] - only when using PyAudio", type=int, default=None, metavar="INT") + group.add_option("-F", "--audio-frame-per-buffer", dest="frame_per_buffer", help="Audio frame per buffer [default: %default] - only when using PyAudio", type=int, default=1024, metavar="INT") parser.add_option_group(group) group = OptionGroup(parser, "[Do something with detections]", "Use these options to print, play or plot detections.") @@ -609,7 +611,9 @@ try: asource = PyAudioSource(sampling_rate = opts.sampling_rate, sample_width = opts.sample_width, - channels = opts.channels) + channels = opts.channels, + frames_per_buffer = opts.frame_per_buffer, + input_device_index = opts.input_device_index) except Exception: sys.stderr.write("Cannot read data from audio device!\n") sys.stderr.write("You should either install pyaudio or read data from STDIN\n")
--- a/auditok/io.py Sat Oct 06 12:02:01 2018 +0200 +++ b/auditok/io.py Thu Nov 01 01:51:44 2018 -0400 @@ -351,10 +351,12 @@ def __init__(self, sampling_rate=DEFAULT_SAMPLE_RATE, sample_width=DEFAULT_SAMPLE_WIDTH, channels=DEFAULT_NB_CHANNELS, - frames_per_buffer=1024): + frames_per_buffer=1024, + input_device_index=None): AudioSource.__init__(self, sampling_rate, sample_width, channels) self._chunk_size = frames_per_buffer + self.input_device_index = input_device_index import pyaudio self._pyaudio_object = pyaudio.PyAudio() @@ -370,6 +372,7 @@ rate=self.sampling_rate, input=True, output=False, + input_device_index=self.input_device_index, frames_per_buffer=self._chunk_size) def close(self):