3 PyAudio example: Record a few seconds of audio and save to a WAVE
13 FORMAT = pyaudio.paInt16
17 WAVE_OUTPUT_FILENAME = "output.wav"
20 if sys.platform == 'darwin':
25 stream = p.open(format=FORMAT,
29 input_device_index=DEVICE,
30 frames_per_buffer=CHUNK)
36 for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
37 data = stream.read(CHUNK, exception_on_overflow=False)
40 print("* done recording")
46 wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
47 wf.setnchannels(CHANNELS)
48 wf.setsampwidth(p.get_sample_size(FORMAT))
50 wf.writeframes(b''.join(frames))