2
PyAudio Example: Low Level C Module test.
4
Record a few seconds of audio and save to a WAVE file.
13
FORMAT = _portaudio.paInt16
17
WAVE_OUTPUT_FILENAME = "output.wav"
19
if sys.platform == 'darwin':
22
print "* initializing"
23
_portaudio.initialize()
26
stream = _portaudio.open(format = FORMAT,
30
frames_per_buffer = chunk)
32
print "* starting stream"
33
_portaudio.start_stream(stream)
38
for i in range(0, 44100 / chunk * RECORD_SECONDS):
39
data = _portaudio.read_stream(stream, chunk)
42
print "* stopping stream"
43
_portaudio.stop_stream(stream)
45
print "* closing stream"
46
_portaudio.close(stream)
48
# match all initialize() with terminate() calls
49
_portaudio.terminate()
51
# write data to WAVE file
54
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
55
wf.setnchannels(CHANNELS)
56
wf.setsampwidth(_portaudio.get_sample_size(FORMAT))