title: Getting IOError: [Errno Invalid number of channels] -9998 when using mic with PyAudio on Raspberry Pi
body: <p>Bad news, everyone!</p>
  
  <p>I try to use a microphone on my Raspberry Pi through PyAudio but without success. The microphone is connected to a USB sound card.</p>
  
  <p>The microphone works when I go through 'arecord' : </p>
  
  <pre><code>pi@raspberrypi ~ $ arecord -D plughw:0,0 -f cd test2.wav
  Recording WAVE 'test2.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
  </code></pre>
  
  <p>However, when I do the test record.py in PyAudio, I got an error. The error is the same for all programs in Python that uses PyAudio :</p>
  
  <pre><code>pi@raspberrypi /usr/src/pyaudio/test $ python record.py 
  ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
  ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
  ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
  ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
  ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
  ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
  ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
  ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
  ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
  ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
  Expression 'parameters-&gt;channelCount &lt;= 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 &lt;module&gt;
  frames_per_buffer=CHUNK)
    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
  </code></pre>
  
  <p>Thanks for your help</p>