#PulseMmonitor.py import pyaudio import numpy as np import matplotlib.pyplot as plt import cv2 def streamandshow(): CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 2 RATE = 44100 RECORD_SECONDS = 0.12 p = pyaudio.PyAudio() stream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True, frames_per_buffer = CHUNK) frames = [] for i in range(int(RATE * RECORD_SECONDS // CHUNK)): data_raw = stream.read(CHUNK) frames.append(data_raw) frames_int16 = np.array(frames) stream.stop_stream() stream.close() p.terminate() data = np.frombuffer(frames_int16, dtype='int16') data_l = data[::2] data_max = max(data_l) print(data_max) fig = plt.figure(num = 1, figsize = (6, 4)) plt.plot(data_l[100:]) plt.pause(0.3) plt.clf() while True: if cv2.waitKey(1) & 0xFF == ord('q'): break streamandshow()