def audio_visualize_1d(self): xf = np.linspace(20, self.rate / 2, self.window) fig, ax = plt.subplots(figsize=(14, 5)) lf, = ax.semilogx(xf, np.zeros(self.window), lw=1, color='lightblue') ax.set_ylim(-0.5, 1.5) ax.set_axis_off() plt.show(block=False) plt.pause(self.record_delay) while self.stream.is_active(): data = self.stream.read(self.window) data_int = struct.unpack(str(self.window * 2) + 'B', data) y_detrend = detrend(data_int) box = np.ones(self.fwhm) / self.fwhm y_smooth = np.convolve(y_detrend, box, mode='same') yft = np.abs(np.fft.fft(y_smooth)) y_vals = yft[:self.window] / (64 * self.window) ind = np.where(y_vals > (np.max(y_vals) + np.min(y_vals)) / 2) y_vals[ind[0]] *= 4 lf.set_ydata(y_vals) try: ax.figure.canvas.draw() ax.figure.canvas.flush_events() except TclError: self.stream.stop_stream() self.stream.close() break