2 PyAudio example: Record a few seconds of audio and save to a WAVE
11 FORMAT = pyaudio.paInt16
15 WAVE_OUTPUT_FILENAME = "output.wav"
18 if sys.platform == 'darwin':
23 stream = p.open(format=FORMAT,
27 input_device_index=DEVICE,
28 frames_per_buffer=CHUNK)
34 for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
35 data = stream.read(CHUNK, exception_on_overflow=False)
38 print("* done recording")
44 wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
45 wf.setnchannels(CHANNELS)
46 wf.setsampwidth(p.get_sample_size(FORMAT))
48 wf.writeframes(b''.join(frames))