import alsaaudio, wave
mixer = alsaaudio.Mixer(control='Mic', cardindex=0)
mixer.setrec(1)
mixer.setvolume(80,  0, alsaaudio.PCM_CAPTURE)
inp = alsaaudio.PCM(type=alsaaudio.PCM_CAPTURE, device='sysdefault:CARD=Headset')
inp.setchannels(1)
inp.setrate(44100)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
inp.setperiodsize(1024)
w = wave.open('test.wav', 'w')
w.setnchannels(1)
w.setsampwidth(2)
w.setframerate(44100)
while True:
    l, data = inp.read()
    w.writeframes(data)

import alsaaudio, wave
mixer = alsaaudio.Mixer(control='Mic', cardindex=0)
mixer.setrec(1)
mixer.setvolume(80,  0, alsaaudio.PCM_CAPTURE)
inp = alsaaudio.PCM(type=alsaaudio.PCM_CAPTURE, device='sysdefault:CARD=Headset')
inp.setchannels(1)
inp.setrate(44100)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
inp.setperiodsize(1024)
w = wave.open('test.wav', 'w')
w.setnchannels(1)
w.setsampwidth(2)
w.setframerate(44100)
while True:
    l, data = inp.read()
    w.writeframes(data)
