width = 1000
data = audio[0, :]
audio_widget = pn.pane.Audio(data, sample_rate=sr, name='Audio', throttle=500)
time = np.linspace(0, len(data) / sr, num=len(data))
line_plot = hv.Curve((time, data), ["time (s)","amplitude"]).opts(width=width)
f, t, sxx = compute_spectrogram(audio, sr)
spec_gram = hv.Image((t, f, np.log10(sxx)), ["time (s)","frequency (hz)"]).opts(width=width)
def interactive_play(x,y,t):
if x is None:
return hv.VLine(t).opts(color='green')
else:
audio_widget.time = x
return hv.VLine(x).opts(color='green')
stream = Params(parameters=[audio_widget.param.time], rename={'time': 't'})
tap = hv.streams.SingleTap(transient=True)
dmap_time = hv.DynamicMap(interactive_play, streams=[stream, tap])
pn.Column( audio_widget, (spec_gram * dmap_time), (line_plot * dmap_time))