import librosa
from google.colab import drive
drive.mount('/content/drive')
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
given a sound file, estimate the beat positions
y, sr = librosa.load('/content/drive/MyDrive/python_scratch/audio/giant_steps_small/1030011.LOFI.mp3', duration=20)
/usr/local/lib/python3.7/dist-packages/librosa/core/audio.py:162: UserWarning: PySoundFile failed. Trying audioread instead. warnings.warn("PySoundFile failed. Trying audioread instead.")
# listen to the audio file
import IPython.display as ipd
from IPython.core.display import display
display(ipd.Audio(y,rate=sr))
# run the beat_track function
bpm, beats = librosa.beat.beat_track(y, sr=sr, hop_length=128)
print(bpm)
print(beats)
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,8)) # set figure size
plt.plot(y) # plot waveform
plt.vlines(beats * 128, -1, 1, color='r') # plot clicks as lines
# make a click track with the beats
click_track = librosa.clicks(frames=beats,sr=sr,hop_length=128, length=len(y))
# and listen to it
display(ipd.Audio(click_track, rate=sr))
# Now combine them into one sound file
y_with_clicks = y + click_track
# and listen to it
display(ipd.Audio(y_with_clicks, rate=sr))
Define a function to play and PLOT the audio + click tracks
def beat_plot_and_play(filename, duration, hop_length):
"""
Plots and plays the tracked Beats from the input filename
"""
Get the beat positions of 10 files of your choosing and compare them.