I like doing visualizations of different types of data, so I started thinking of doing something simple with the audio information of songs. With this in mind, I started playing around with a couple of packages in python and decided on plotting waveforms in a visually appealing way.
Loading into pydub
First step was to load audio into Python using the pydub library in our main script:
One thing to note in getFileAndSongNames is that we are loading the song name as it is stored in the file’s metadata, not necessarily on the filename. After doing this, we mix together the two channels (L and R) of the song into the same array:
Although we could theoretically plot the wave as it is, we want it to look nice, so we define a function that creates a matplotlib colormap that changes linearly from one color, into white, and then into another color. These colors are sampled randomly from a pool defined by the user in the style file:
Finally, we do a scatterplot of all the values of the array that represents the waveform and we tweak style parameters to make it more visually appealing:
With these steps in place, we put it all together in a script that runs through audio files stored in a folder in batch mode with options to change the fonts and styles!