def plot_data(audio_files,frame, window_type, nfft, step, fmin, fmax, chunk = None, detections=None, detections_channel=0): graph_spectros = GrapherFactory('SoundPlotter', title='Spectrograms', frequency_max=fmax) graph_waveforms = GrapherFactory('SoundPlotter', title='Waveforms') for audio_file, channel in zip(audio_files['path'], audio_files['channel'] ): # for each channel # load waveform sound = Sound(audio_file) sound.read(channel=channel, chunk=chunk, unit='sec', detrend=True) # Calculates spectrogram spectro = Spectrogram(frame, window_type, nfft, step, sound.waveform_sampling_frequency, unit='sec') spectro.compute(sound, dB=True, use_dask=False) # Crop unused frequencies spectro.crop(frequency_min=fmin, frequency_max=fmax, inplace=True) # Plot graph_spectros.add_data(spectro, time_offset_sec=chunk[0]) graph_waveforms.add_data(sound, time_offset_sec=chunk[0]) graph_spectros.colormap = 'binary' if detections: graph_spectros.add_annotation(detections, panel=detections_channel, color='green',label='Detections') graph_waveforms.add_annotation(detections, panel=detections_channel, color='green',label='Detections') if chunk: graph_spectros.time_min = chunk[0] graph_spectros.time_max = chunk[1] graph_waveforms.time_min = chunk[0] graph_waveforms.time_max = chunk[1] graph_spectros.show() graph_waveforms.show()
def plot_spectrogram(audio_file,loc,t1_sec, t2_sec, geometry=(1,1,1)): fmin=0 fmax=1000 frame= 0.0625 window_type= 'hann' nfft=0.0853 step=0.01 channel=0 chunk=[t1_sec,t2_sec] graph_spectros = GrapherFactory('SoundPlotter', title='Spectrograms', frequency_max=fmax) sound = Sound(audio_file) sound.read(channel=channel, chunk=chunk, unit='sec', detrend=True) # Calculates spectrogram spectro = Spectrogram(frame, window_type, nfft, step, sound.waveform_sampling_frequency, unit='sec') spectro.compute(sound, dB=True, use_dask=False) # Crop unused frequencies spectro.crop(frequency_min=fmin, frequency_max=fmax, inplace=True) # Plot graph_spectros.add_data(spectro) #graph_spectros.add_annotation(loc, panel=0, color='burlywood',label='Detections') graph_spectros.add_annotation(loc, panel=0, color='peachpuff') graph_spectros.colormap = 'binary' #'jet' fig, ax = graph_spectros.show() if ax.get_geometry() != geometry : ax.change_geometry(*geometry) return fig, ax
# # Plot graph = GrapherFactory('SoundPlotter', title='Recording', frequency_max=5000) # graph.add_data(sound) # #graph.add_annotation(classif_fish, panel=0,color='red', label='Fish', tag=True) # graph.add_data(spectro1) # graph.add_data(spectro2) graph.add_data(spectro2) # graph.add_data(spectro2) graph.add_annotation(detections, panel=0,color='red', label='Detections') # graph.add_annotation(classif_fish, panel=4,color='red', label='Fish', tag=True) # graph.add_annotation(classif_noise, panel=4,color='blue', label='Noise',tag=True) # graph.colormap = 'binary' graph.colormap = 'jet' graph.show() # classifier = Classifier() # classifier.load_model(model_filename) # classif2 = classifier.classify(measurements) # # Plot # graph = GrapherFactory('SoundPlotter', title='Recording', frequency_max=1000) # graph.add_data(sound) # #graph.add_annotation(classif_fish, panel=0,color='red', label='Fish', tag=True) # graph.add_data(spectro1) # graph.add_data(spectro2) # graph.add_data(spectro2) # graph.add_data(spectro2)