title: Taking audio input from PC microphone using python
body: <p>I am using ubuntu 16.04 and I have to take audio input from my pc microphone. I am using python 3. I used pyalsaaudio. I copied the code from somewhere. Here is the code</p>
  
  <pre><code>import alsaaudio, time, audioop
  inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE,alsaaudio.PCM_NONBLOCK)
  inp.setchannels(1)
  inp.setrate(8000)
  inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
  inp.setperiodsize(160)
  while True:
      l,data = inp.read()
      if l:
         print(audioop.max(data, 2))
      time.sleep(.001)
  </code></pre>
  
  <p>By using this code I am getting an error as</p>
  
  <blockquote>
    <p>ALSAAudioError: Invalid argument</p>
  </blockquote>
  
  <p>In line no. 3 inp.setchannels(1)</p>
  
  <p>I am new to this if there is another library for doing this then please suggest that too.
  Thanks.</p>