Given an MP3 I would like to extract the waveform from the file into an image (.png)
Is there a package that can do what I need ?
Given an MP3 I would like to extract the waveform from the file into an image (.png)
Is there a package that can do what I need ?
I would do something like this :
find a tool to convert mp3 to PCM, ie binary data with one 8 or 16 bit value per sample. I guess mplayer can do that
pipe the result to a utility converting binary data to an ascii representation of the numbers in decimal format
use gnuplot to transform this list of value into a png graph.
And voilà, the power of piping between unix tools. Now Step 2 in this list might be optionnal if gnuplot is able to read it's data from a binary format.
This is a standard function in SoX (command line tool for sound, Windows & Linux) Check the 'spectrogram' function on http://sox.sourceforge.net/sox.html
"The spectrogram is rendered in a Portable Network Graphic (PNG) file, and shows time in the X-axis, frequency in the Y-axis, and audio signal magnitude in the Z-axis. Z-axis values are represented by the colour (or optionally the intensity) of the pixels in the X-Y plane. If the audio signal contains multiple channels then these are shown from top to bottom starting from channel 1 (which is the left channel for stereo audio)."
Using
sox
andgnuplot
you can create basic waveform images:To create something simpler/prettier, use the following GNU Plot file as a template (save it as audio.gpi):
and just run:
Based on this answer to a similar question that is more general regarding file format but less general in regards to software used.
If you have a GUI environment you can use the audacity audio editor to load the mp3 and then use the print command to generate a pdf of the waveform. Then convert the pdf to png.
You might want to consider audiowaveform from the BBC.
https://github.com/bbcrd/audiowaveform