from scipy.signal import spectrogram
from scipy.io import wavfile
from bokeh.resources import INLINE
hv.extension("bokeh", logo=False)
def save_audio_with_bokeh_plot_to_html(audio_path, html_file_name):
sr, wav_data = wavfile.read(audio_path)
duration = len(wav_data)/sr
f, t, sxx = spectrogram(wav_data, sr)
spec_gram = hv.Image((t, f, np.log10(sxx)), ["Time (s)", "Frequency (hz)"]).opts(width=500, height=150, labelled=[])
audio = pn.pane.Audio(wav_data, sample_rate=sr, name='Audio', throttle=500)
slider = pn.widgets.FloatSlider(end=duration, visible=False)
line = hv.VLine(0).opts(color='white')
slider.jslink(audio, value='time', bidirectional=True)
slider.jslink(line, value='glyph.location')
combined = pn.Row(audio, spec_gram * line, slider).save(html_file_name)
html_file_name = 'audio_with_plot.html'
save_audio_with_bokeh_plot_to_html(audio_path, html_file_name)
wandb_html = wandb.Html(html_file_name)
run = wandb.init(project='audio_test')
my_table = wandb.Table(columns=['audio_with_plot'], data=[[wandb_html], [wandb_html]])
run.log({"audio_table": my_table})