How can I create a waveform image of an MP3 in Linux? How can I create a waveform image of an MP3 in Linux? linux linux

How can I create a waveform image of an MP3 in Linux?


Using sox and gnuplot you can create basic waveform images:

sox audio.mp3 audio.dat #create plaintext file of amplitude valuestail -n+3 audio.dat > audio_only.dat #remove comments# write script file for gnuplotecho set term png size 320,180 > audio.gpi #set output formatecho set output \"audio.png\" >> audio.gpi #set output fileecho plot \"audio_only.dat\" with lines >> audio.gpi #plot datagnuplot audio.gpi #run script

enter image description here

To create something simpler/prettier, use the following GNU Plot file as a template (save it as audio.gpi):

#set output format and sizeset term png size 320,180#set output fileset output "audio.png"# set y rangeset yr [-1:1]# we want just the dataunset keyunset ticsunset borderset lmargin 0             set rmargin 0set tmargin 0set bmargin 0# draw rectangle to change background colorset obj 1 rectangle behind from screen 0,0 to screen 1,1set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "#222222"# draw data with foreground colorplot "audio_only.dat" with lines lt rgb 'white'

and just run:

sox audio.mp3 audio.dat #create plaintext file of amplitude valuestail -n+3 audio.dat > audio_only.dat #remove commentsgnuplot audio.gpi #run script

enter image description here

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.


I would do something like this :

  • find a tool to convert mp3 to PCM, ie binary data with one 8 or 16 bit valueper sample. I guess mplayer can do that

  • pipe the result to a utility converting binary data to an asciirepresentation 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.