Show the code
import numpy as np
import librosa
import librosa.display
import IPython.display as ipd
from matplotlib import pyplot as plt
import numpy as np
import librosa
import librosa.display
import IPython.display as ipd
from matplotlib import pyplot as plt
= librosa.load('data/help.mp3', offset=1.05, duration=10.087)
x, sr =x, rate=sr)) ipd.display(ipd.Audio(data
= plt.subplots(nrows=1,figsize=(7.5, 2.75))
fig, ax =sr, ax=ax, color='indigo')
librosa.display.waveshow(x, sr
"Waveform")
ax.set_title("Time (s)")
ax.set_xlabel("Amplitude")
ax.set_ylabel(range(0, 11, 1))
ax.set_xticks(0, 10])
ax.set_xlim([
ax.grid()
fig.tight_layout() plt.show()
= plt.subplots(nrows=1, figsize=(7.5, 2.75))
fig, ax = librosa.feature.rms(y=x) # Extra dynamics (RMS)
rms = librosa.amplitude_to_db(rms, ref=np.max) # Convert into dB. Note that this is a relative measure (loudest is now 0)
db = librosa.times_like(rms)
times
0], color='darkblue')
ax.plot(times, db["Loudness")
ax.set_title(-15,0])
ax.set_ylim(["Decibel")
ax.set_ylabel("Time (s)")
ax.set_xlabel(range(0, 11, 1))
ax.set_xticks(0, 10])
ax.set_xlim([
ax.grid()
fig.tight_layout() plt.show()
= plt.subplots(nrows=1, figsize=(7.5, 2.75))
fig, ax
= librosa.onset.onset_strength_multi(y=x,
onset_subbands =sr,
sr=[0, 32, 64, 96, 128])
channels
= sum(onset_subbands, 1)
onset_subbands_s 'maroon')
ax.plot(times, onset_subbands_s,
= librosa.beat.beat_track(y=x, sr=sr, trim=False)
tempo, beats 0, onset_subbands_s.max(), color='0.40', alpha=0.80,
plt.vlines(times[beats], ='--', label='Beats')
linestyle
= librosa.onset.onset_strength(y=x, sr=sr)
o_env = librosa.times_like(o_env, sr=sr)
times = librosa.onset.onset_detect(onset_envelope=o_env, sr=sr)
onset_frames
"Onset strength and estimated beats")
ax.set_title("Strength")
ax.set_ylabel("Time (s)")
ax.set_xlabel(0, 60])
ax.set_ylim([range(0, 11, 1))
ax.set_xticks(0, 10])
ax.set_xlim([
ax.grid()
fig.tight_layout()
= np.loadtxt('data/Help_beats.csv')
data = data[0:16, 0]-1.05
ann_time = data[0:16, 1]
ann_label for x in range(16):
53, int(ann_label[x]), size=6,
ax.text(ann_time[x], ='0.8', weight='bold', ha='center')
backgroundcolor
plt.show()