Last active
August 29, 2015 14:16
-
-
Save neokril/7509c352834c75eccb11 to your computer and use it in GitHub Desktop.
Simple multidevice recorder for windows 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyaudio | |
import wave | |
from time import sleep | |
CHUNK = 1024 | |
FORMAT = pyaudio.paInt16 | |
CHANNELS = 2 | |
RATE = 48000 | |
RECORD_SECONDS = 5 | |
WAVE_OUTPUT_FILENAME = ["output.wav", | |
"output2.wav"] | |
DEVICES = [1, 5] # put device IDs here (see below) | |
p = pyaudio.PyAudio() | |
def getCb(i, frames): | |
def cb(data, nframes, time, status): | |
frames.append(data) | |
#print nframes | |
if len(frames) > int(RATE / CHUNK * RECORD_SECONDS): | |
print "stop" | |
return (None, pyaudio.paComplete) | |
return (None, pyaudio.paContinue) | |
return cb | |
def main(): | |
for i in range(11): | |
f = p.get_device_info_by_index(i) | |
if f['maxOutputChannels'] == 0: | |
print i, f['name'] #choose a device you want to use and put its id into DEVICES | |
s = [0, 0] # streams | |
frames = [[], []] | |
for i, d in enumerate(DEVICES): | |
s[i] = p.open(format=FORMAT, | |
channels=CHANNELS, | |
rate=RATE, | |
input=True, | |
frames_per_buffer=CHUNK, | |
input_device_index=d, | |
stream_callback=getCb(i, frames[i])) | |
while s[0].is_active(): | |
sleep(1) | |
p.terminate() | |
for i, fname in enumerate(WAVE_OUTPUT_FILENAME): | |
wf = wave.open(fname, 'wb') | |
wf.setnchannels(CHANNELS) | |
wf.setsampwidth(p.get_sample_size(FORMAT)) | |
wf.setframerate(RATE) | |
wf.writeframes(b''.join(frames[i])) | |
wf.close() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only one dependancy - pyaudio: http://people.csail.mit.edu/hubert/pyaudio/