3 PyAudio example: Record a few seconds of audio and save to a WAVE
12 FORMAT = pyaudio.paInt16
16 WAVE_OUTPUT_FILENAME = "output.wav"
19 if sys.platform == 'darwin':
24 stream = p.open(format=FORMAT,
28 input_device_index=DEVICE,
29 frames_per_buffer=CHUNK)
35 for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
36 data = stream.read(CHUNK, exception_on_overflow=False)
39 print("* done recording")
45 wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
46 wf.setnchannels(CHANNELS)
47 wf.setsampwidth(p.get_sample_size(FORMAT))
49 wf.writeframes(b''.join(frames))