I am using a raspberry pi model B with a Logitech USB Microphone, and I have python version 2.7.3 and a new install of pyaudio version 0.2.8. When I try and run the record.py file located in the test folder provided when pyaudio was downloaded, I get this error

    ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
Expression 'parameters->channelCount <= maxChans' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1438
Expression 'ValidateParameters( inputParameters, hostApi, StreamDirection_In )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2742
Traceback (most recent call last):
  File "record.py", line 26, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 747, in open
    stream = Stream(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 442, in __init__
    self._stream = pa.open(**arguments)
IOError: [Errno Invalid number of channels] -9998

I was not able to find any working answers on google.

Any help would be greatly appricated.

2 Answers 2


Indeed the question do not provide relevant details. Anyway, I walked with similar issue and I just realize that the problem, at least for me, was that I was using the wrong (nonexistent, default) device. So I just passed the device index as the argument of the open call:

stream = p.open(format=FORMAT,input_device_index = INDEX,

Where INDEX is 2 for me. I have obtained this index listing the devices with:

for i in range(p.get_device_count()):

Remember to import and initialize the pyaudio before run the previous code:

import pyaudio
p = pyaudio.PyAudio()

If you have problems like "jack server is not running or cannot be started" just manually start the jackd:

jackd -r -m -p 8 -d dummy

In the pyaudio code there is CHANNELS = 2 this is used for recording the sound stream = p.open(format=FORMAT,channels=CHANNELS,rate=RATE,input=True,frames_per_buffer=CHUNK), by changing this to CHANNELS = 1 it started working and recording audio

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.