PHP MP3 SVG waveform generator
Switch branches/tags
Nothing to show
Pull request Compare This branch is even with afreiday:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE
README.md
php-waveform-svg.php
waveform.css

README.md

PHP MP3 SVG Waveform Generator

About

Generates SVG waveform images for a given MP3 file by converting it to WAV and processing amplitude points and plotting them as an SVG XML file.

This code was adapted by Andrew Freiday.

Based on the PHP MP3 Waveform Generator.

Requirements

Usage/Installation

  • Copy to a location on your web server
  • Ensure that the 'lame' command is accessible and executable from that directory (for Windows systems, place the downloaded .exe and .dll as linked above into that same directory, or modify the script)
  • Ensure the directory support write persmissions, or specify an alternate temporary output directory that does
  • Launch the script in your browser (e.g. http://localhost/php-waveform-svg.php) and upload your MP3
  • Modify waveform.css to change the display colours/properties of your SVG waveform

Image generation options

  • The "stereo waveform" option allows you to generate a single SVG image with both left and right audio channels separately

Other notes

The detail of the waveform can be adjusted by modifying the DETAIL constant at the top of the script. The lower the number, the less data points are skipped, thus resulting in higher detail waveform.

The most time-consuming factor of the script is the LAME encoder, which first converts the uploaded MP3 into a 16 bit, mono, 8 KHz MP3 and finally to a WAV audio file. Unfortunately this doesn't seem to be possible to perform this in one step with the LAME encoder. If this script is to be modified to generate waveforms on the fly for the same MP3 multiple times, I recommend either storing a copy of the final WAV file or modifying the script to keep a dataset of the amplitude points so that the waveform can be redrawn much more quickly.

License

Please see the LICENSE file.