Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Audio to visualize and interact with waveforms

Tags:

How do I write a JavaScript program to display a waveform from an audio file? I want to use Web Audio and Canvas.

I tried this code:

(new window.AudioContext).decodeAudioData(audioFile, function (data) {    var channel = data.getChannelData(0);    for (var i = 0; i < channel; i++) {        canvas.getContext('2d').fillRect(i, 1, 40 - channel[i], 40);    } }); 

But the result is far from what I want (namely, the image is not smooth since I'm drawing with rectangles). I want it to look smooth like this image:

Waveform example

Any hints on how to implement the waveform?

like image 306
katspaugh Avatar asked Mar 01 '12 12:03

katspaugh


People also ask

What does Web Audio API do?

The Web Audio API involves handling audio operations inside an audio context, and has been designed to allow modular routing. Basic audio operations are performed with audio nodes, which are linked together to form an audio routing graph.

Which statement about Web Audio API of HTML5 is true?

Q 2 - Which of the following is true about 'audio' tag in HTML5? A - HTML5 supports <audio> tag which is used to embed sound content in an HTML or XHTML document.

What is audio waveform?

An audio wave is the vibration of air molecules, which is how sound travels. A waveform describes a wave by graphing how an air molecule is displaced, over time. Amplitude is the strength of a wave's effect; the higher the amplitude, the more the air molecules are displaced.


2 Answers

Rolled out my own library after all: wavesurfer.js.

It draws a waveform from PCM data and seeks regions of the audio by clicking on it.

Imgur

like image 145
katspaugh Avatar answered Oct 08 '22 18:10

katspaugh


You may be interested in AudioJedit. This is an open source project hosted at GitHub. It have small server-side node.js script for loading audio files, but all interaction with audio implemented in client-side JavaScript. I think this is similar to what you are looking for.

like image 36
Vadim Baryshev Avatar answered Oct 08 '22 17:10

Vadim Baryshev