def audio_visualize_2d(self): t = np.linspace(0, 2. * np.pi, self.window * 2) xf = np.cos(t) yf = np.sin(t) fig, ax = plt.subplots(figsize=(7, 7)) lf, = ax.plot(xf, yf, lw=1, color='lightblue') ax.set_xlim(-3, 3) ax.set_ylim(-3, 3) 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) yft = np.abs(np.fft.fft(y_detrend)) y_vals = yft / (64 * self.window) ind = np.where(y_vals > (np.max(y_vals) + np.min(y_vals)) / 2) y_vals[ind[0]] *= 4 lf.set_xdata(xf + y_vals * np.cos(t)) lf.set_ydata(yf + y_vals * np.sin(t)) try: ax.figure.canvas.draw() ax.figure.canvas.flush_events() except TclError: self.stream.stop_stream() self.stream.close() break