Generate Waveform from music file with PHP

Recently I was working on one project which required processing a audio file and generating “wave” file for that audio file so that can it can be displayed nicely on front end.

So in this post I will share it with you all how to generate waveform for audio file using PHP only.

For our production server, we needed other software as well to convert audio file to .wav file which basically contains raw information about the audio file and makes it very easy to fetch information.

You can view the source code for generating waveform in github.

Rather then writing code from scratch, I was using one library called AudioFile which basically takes audio file as its input and modifies that generates PNG/JPEG file for waveform.

I have made some modification in original AudioFIle class to suit my need for generating elegaent waveform and minimize the wave point for optimal performance.

Original AudioFile PHP Class had option only to generate PNG/JPEG filess only, there was no support for SVG file, so I created new function in that file to generate SVG files based on data point which for calculated for PNG/JPEG files.

Here is the modified method for generating SVG file

Thanks for reading…

Leave a Reply