Waveform visualization in JavaScript from audio

Alex picture Alex · May 29, 2011 · Viewed 26.9k times · Source

I'm trying to use JavaScript to display the waveform for and audio file, but I don't even know how to get started. I found the Audio Data API, but am unfamiliar with most audio terms and don't really know what is provided or how to manipulate it. I found examples of waveforms in JavaScript, but they are too complicated/I can't comprehend what is going on. Then my question is: how can you use JavaScript to create a waveform of a song on canvas, and what exactly is the process behind it?

Answer

Ian Devlin picture Ian Devlin · Feb 2, 2012

Here's some sample code from my book (HTML5 Multimedia: Develop and Design) that does exactly that; Audio Waveform. It uses the Mozilla Audio Data API.

The code simply takes snapshots of the audio data and uses it to draw on the canvas.