Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  142] [ 1]  / answers: 1 / hits: 15931  / 13 Years ago, thu, march 1, 2012, 12:00:00

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



Any hints on how to implement the waveform?


More From » html

 Answers
15

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.


[#87111] Wednesday, February 29, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alekgermanb

Total Points: 616
Total Questions: 86
Total Answers: 105

Location: Aland Islands
Member since Thu, Dec 23, 2021
2 Years ago
;