Prepare Python (and colab)

Audio to Score Alignment

Here's an example of audio-to-score alignment using the DTW algorithm. Two python classes are constructed, a Score and an Aligner class. The Score is used to maintain a music21 score with its audio version in sync, so as to query sections of the audio by measures. The Aligner class is meant to ease the usage of the DTW algorithm.

Getting Bach Chorales (...from youtube)

Get some youtube URLs

Getting a Bach Chorale Score (from kern to synced audio+music21)

Score class

Usage

Aligning source and target for querying

Aligner class

Usage

Python Classes

A class in python is a way to structure your data, as well as your functions. Creating a new class creates a new type of object, allowing new instances of that type to be made.

Composer class

Instantiate the class:

Check what's inside the class attribute name:

Change data inside the instance:

Instantiate the class again to a different variable:

Check what's inside:

Classes have a 'self'

These selves need to be initialized, though.

How are Classes different than variables? Functions

Exercise

Add a spectrogram plotting function to the BPM class

1. (REVIEW) Put this into a function called plot_spectrogram

(review) Run the function on several files:

2. Place the function inside this (slightly changed) BPM class creation

This would result in a plotted spectrogram, and the bpm printed to screen: