javascript - Read samples from wav-file -


i'm trying make webpage in html5 stores sample-data wav-file in array. there way sample-data javascript? i'm using file-input select wav-file.

in javascript added:

document.getelementbyid('fileinput').addeventlistener('change', readfile, false); 

but have no idea in readfile.

edit: tried file in arraybuffer, pass decodeaudiodata method , typedarraybuffer out of it. code:

var openfile = function(event) { var input = event.target; var audiocontext = new audiocontext();  var reader = new filereader(); reader.onload = function(){ var arraybuffer = reader.result;   console.log("arraybuffer:");   console.log(arraybuffer);   audiocontext.decodeaudiodata(arraybuffer, decodeddone);  }; reader.readasarraybuffer(input.files[0]); }; function decodeddone(decoded) { var typedarray = new uint32array(decoded, 1, decoded.length);   console.log("decoded");   console.log(decoded);   console.log("typedarray");   console.log(typedarray);  (i=0; i<10; i++) {     console.log(typedarray[i]); }  } 

the elements of typedarray 0. way of creating typedarray wrong or did else wrong on?

edit: got it. code:

var openfile = function(event) { var input = event.target; var audiocontext = new audiocontext();  var reader = new filereader(); reader.onload = function(){ var arraybuffer = reader.result;   console.log("arraybuffer:");   console.log(arraybuffer);   audiocontext.decodeaudiodata(arraybuffer, decodeddone);  }; reader.readasarraybuffer(input.files[0]); }; function decodeddone(decoded) {   var typedarray = new float32array(decoded.length);  typedarray=decoded.getchanneldata(0); console.log("typedarray:"); console.log(typedarray);  } 

thanks answers!

you'll need learn lot web apis accomplish that, in end it's quite simple.

  1. get file contents in arraybuffer file api
  2. pass web audio api's decodeaudiodata method.
  3. get typed arraybuffer raw samples wanted.

edit: if want implement equalizer, you're wasting time, there's native equalizer node in audio api. depending on length of wave file might better not load in memory , instead create source reads , connect source equalizer node.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -