title: Can't record more than one wave with pyaudio (no default output device)
body: <p>I'm trying to write the most simple program to take two recordings and record two wave files. You can get the raw code: <a href="https://gist.github.com/579095ac89fa2fff58db" rel="nofollow noreferrer">https://gist.github.com/579095ac89fa2fff58db</a></p>
  
  <pre>
  import pyaudio
  import wave
  
  CHUNK = 1024
  FORMAT = pyaudio.paInt16
  CHANNELS = 1
  RATE = 44100
  p = pyaudio.PyAudio()
  
  def record(file_name):
  
    stream = p.open(format = FORMAT,
      channels = CHANNELS,
      rate = RATE,
      input = True,
      frames_per_buffer = CHUNK)
  
    frames = []
    print "starting recording " + file_name + "."
    for i in range(0, int(RATE / CHUNK * 2)):
      data = stream.read(CHUNK)
      frames.append(data)
    print "finished recording"
  
    stream.stop_stream()
    stream.close()
    p.terminate()
  
    wf = wave.open(file_name, 'wb')
    wf.setnchannels(CHANNELS)
    wf.setsampwidth(p.get_sample_size(FORMAT))
    wf.setframerate(RATE)
    wf.writeframes(b''.join(frames))
    wf.close()
  
  record('first.wav')
  # try again
  record('second.wav')
  </pre>
  
  <p>Everything works fine if I only call the record function once, but if I try to call it again, I get: IOError: [Errno -9996] Invalid input device (no default output device).</p>
  
  <pre><code>python record2x.py
  starting recording first.wav.
  finished recording
  Traceback (most recent call last):
    File "record2x.py", line 38, in &lt;module&gt;
      record('second')
    File "record2x.py", line 16, in record
      frames_per_buffer = CHUNK)
    File "/usr/local/lib/python2.7/site-packages/pyaudio.py", line 750, in open
      stream = Stream(self, *args, **kwargs)
    File "/usr/local/lib/python2.7/site-packages/pyaudio.py", line 441, in __init__
      self._stream = pa.open(**arguments)
  IOError: [Errno -9996] Invalid input device (no default output device)
  </code></pre>