Skip to content

Instantly share code, notes, and snippets.

@pklazy
Created May 21, 2014 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pklazy/39da58c8917f5821abaf to your computer and use it in GitHub Desktop.
Save pklazy/39da58c8917f5821abaf to your computer and use it in GitHub Desktop.
만들어진 파일은 'aplay -r 44100 -f S16_LE -c 1 test.raw'로 재생.
import time
import alsaaudio
f = open('test.raw', 'wb')
card = alsaaudio.cards()[1]
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, card)
inp.setchannels(1)
inp.setrate(44100)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
inp.setperiodsize(160)
for i in range(1000000):
l, data = inp.read()
if l:
f.write(data)
time.sleep(.001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment