I'm trying to write the most simple program to take two recordings and record two wave files. You can get the raw code: https://gist.github.com/579095ac89fa2fff58db
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')
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).
python record2x.py
starting recording first.wav.
finished recording
Traceback (most recent call last):
File "record2x.py", line 38, in <module>
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)