def main(): # Launch the stream and the original spectrogram stream, pa = open_mic() try: animation = make_plot(stream) plt.show() finally: stream.stop_stream() stream.close() pa.terminate()
def main(): global im ############### Initialize Plot ############### fig = plt.figure() """ Launch the stream and the original spectrogram """ stream, pa = mic_read.open_mic() data = get_sample(stream, pa) arr2D, freqs, bins = get_specgram(data, rate) """ Setup the plot paramters """ extent = (bins[0], bins[-1] * SAMPLES_PER_FRAME, freqs[-1], freqs[0]) im = plt.imshow(arr2D, aspect='auto', extent=extent, interpolation="none", cmap='Greys', norm=None) plt.xlabel('Time (s)') plt.ylabel('Frequency (Hz)') plt.title('Real Time Spectogram') plt.gca().invert_yaxis() #plt.colorbar() #enable if you want to display a color bar ############### Animate ############### anim = animation.FuncAnimation(fig, update_fig, blit=True, interval=mic_read.CHUNK_SIZE / 1000) try: plt.show() except: print("Plot Closed") ############### Terminate ############### stream.stop_stream() stream.close() pa.terminate() print("Program Terminated")
im_data = np.hstack((im_data, arr2D)) im.set_array(im_data) else: keep_block = arr2D.shape[1] * (SAMPLES_PER_FRAME - 1) im_data = np.delete(im_data, np.s_[:-keep_block], 1) im_data = np.hstack((im_data, arr2D)) im.set_array(im_data) return im, ############### Initialize Plot ############### fig = plt.figure() """ Launch the stream and the original spectrogram """ stream, pa = mic_read.open_mic() data = get_sample(stream, pa) arr2D, freqs, bins = get_specgram(data, rate) """ Setup the plot paramters """ extent = (bins[0], bins[-1] * SAMPLES_PER_FRAME, freqs[-1], freqs[0]) im = plt.imshow(arr2D, aspect='auto', extent=extent, interpolation="none", cmap='jet', norm=LogNorm(vmin=.01, vmax=1)) plt.xlabel('Time (s)') plt.ylabel('Frequency (Hz)') plt.title('Real Time Spectogram')
def main(): global im global stream global pa global model global fig ############### Initialize Plot ############### # Load the Tensorlow model config = Config("model_arrl3.yaml") model = Model( open(config.value("experiment.fnCharList")).read(), config, decoderType=DecoderType.BeamSearch, #,DecoderType.BestPath mustRestore=True, ) """ Launch the stream and the original spectrogram """ stream, pa = mic_read.open_mic() data = get_sample(stream, pa) arr2D, freqs, bins = get_specgram(data, rate) """ Setup the spectrogram plot and textbox for the decoder """ fig, (axbox, ax) = plt.subplots(2, 1) text_box = TextBox(axbox, "Morse:") extent = (bins[0], bins[-1] * SAMPLES_PER_FRAME, freqs[-1], freqs[0]) im = ax.imshow( arr2D, aspect="auto", extent=extent, interpolation="none", cmap="Greys", norm=None, ) plt.xlabel("Time (s)") plt.ylabel("Frequency (Hz)") plt.title("Real Time Spectogram") plt.gca().invert_yaxis() # plt.colorbar() #enable if you want to display a color bar ############### Animate ############### anim = animation.FuncAnimation(fig, update_fig, blit=False, interval=mic_read.CHUNK_SIZE / 1000, fargs=(text_box, )) try: plt.show() except: print("Plot Closed") ############### Terminate ############### stream.stop_stream() stream.close() pa.terminate() print("Program Terminated")
def start(self): ############### Initialize Plot ############### # Set up figure size fig = plt.figure(figsize=(0.64, 0.64)) # Load CNN .h5 model model = load_model('Model/Spectogram_15|09|2020_v2.h5') # Launch the stream and the original spectrogram stream, pa = mic_read.open_mic() data = self.get_sample(stream, pa) arr2D, freqs, bins = self.get_specgram(data, self.rate) # Setup the plot paramters extent = (bins[0], bins[-1] * self.SAMPLES_PER_FRAME, freqs[-150], freqs[20]) im = plt.imshow(arr2D, aspect='auto', extent=extent, interpolation="none", cmap='gray', norm=LogNorm(vmin=.01, vmax=1)) # get clear matplotlib spectogram plt.gca().invert_yaxis() plt.gca().axes.get_xaxis().set_visible(False) plt.gca().axes.get_yaxis().set_visible(False) plt.text(2.85, 2.9, 'label', bbox={ 'facecolor': 'white', 'edgecolor': 'none', 'pad': 10 }) # Setup PySimpleGUI layout and window """ sg.theme('DarkAmber') layout = [[sg.Text(self.prediction, size=(10, 1), font=('Helvetica', 36), text_color='white', key='_Note_')], [sg.Text("stopwatch", font=('Helvetica', 16), text_color='white', key='stopwatch')], [sg.Button('Exit', size=(5, 1), font=('Helvetica', 16))]] window = sg.Window('Note detector', layout, size=(320, 320)) """ # Continously calls update_fig function to get new spectrogram count = -1 try: while self.bool: a += 1 # Update function requires integer input count += 1 # Update figure self.update_fig(count, stream, pa, fig, model, window, im) # Convert matplotlib Object to 3D numpy Array img_pred = np.expand_dims(self.matplotlib_to_numpy(fig), axis=0) # Predict based on model rslt = np.argmax(model.predict(img_pred), axis=1) # Show predicition result self.show_predicition(rslt) #print(a) except KeyboardInterrupt: # close the stream stream.stop_stream() stream.close() pa.terminate() print("Program Terminated") pass
if n < SAMPLES_PER_FRAME: im_data = np.hstack((im_data,arr2D)) im.set_array(im_data) else: keep_block = arr2D.shape[1]*(SAMPLES_PER_FRAME - 1) im_data = np.delete(im_data,np.s_[:-keep_block],1) im_data = np.hstack((im_data,arr2D)) im.set_array(im_data) return im, ############### Initialize Plot ############### fig = plt.figure() """ Launch the stream and the original spectrogram """ stream,pa = mic_read.open_mic() data = get_sample(stream,pa) arr2D,freqs,bins = get_specgram(data,rate) """ Setup the plot paramters """ extent = (bins[0],bins[-1]*SAMPLES_PER_FRAME,freqs[-1],freqs[0]) im = plt.imshow(arr2D,aspect='auto',extent = extent,interpolation="none", cmap = 'jet',norm = LogNorm(vmin=.01,vmax=1)) plt.xlabel('Time (s)') plt.ylabel('Frequency (Hz)') plt.title('Real Time Spectogram') plt.gca().invert_yaxis() ##plt.colorbar() #enable if you want to display a color bar ############### Animate ###############