download - Web Audio API downloading encoded audio -


i trying decode audio file, apply effect, encode again .wav format user can save file computer.

at moment when press "play" button sound plays should, no download box popping up, user download encoded file.

<!doctype html>  <html>    <head>     <meta charset="utf-8"/>      <title>offlineaudiocontext example</title>      <script src="recorder.js"></script>    </head>    <body>      <button class="play">play</button>     <script>  // define online , offline audio context  var audioctx = new audiocontext(); var offlinectx = new offlineaudiocontext(2,44100*10,44100);  // define variables  var myscript = document.queryselector('script'); var play = document.queryselector('.play'); var stop = document.queryselector('.stop');   // decodeaudiodata decode audio create buffer       function getdata() {          request = new xmlhttprequest();          request.open('get', 'kick.mp3', true);          request.responsetype = 'arraybuffer';           request.onload = function() {          var audiodata = request.response;          audioctx.decodeaudiodata(audiodata, function(buffer) {          var source = offlinectx.createbuffersource();          source.buffer = buffer;         source.connect(offlinectx.destination);         source.start();       //source.loop = true;          offlinectx.startrendering().then(function(renderedbuffer) {         console.log('rendering completed successfully');         var audioctx = new (window.audiocontext || window.webkitaudiocontext)();          var song = audioctx.createbuffersource();         song.buffer = renderedbuffer;          song.connect(audioctx.destination);          play.onclick = function() {              song.start(0);             sendwavetopost(renderedbuffer);          }      function sendwavetopost(buffer) {         var worker = new worker('recorderworker.js');          // initialize new worker         worker.postmessage({         command: 'init',         config: {         samplerate: 44100      }   });     // callback `exportwav`     // send channel data our buffer worker     worker.postmessage({         command: 'record',         buffer: [             buffer.getchanneldata(0),             buffer.getchanneldata(1)         ] });    // ask worker wav     worker.postmessage({         command: 'exportwav',         type: 'audio/wav'      });          worker.onmessage = function(e) {          recorder.forcedownload(e.data, 'somefilename.wav');   };  }                }).catch(function(err) {           console.log('rendering failed: ' + err);           // note: promise should reject when startrendering called second time on offlineaudiocontext       });     });   }    request.send();  }  // run getdata start process off  getdata();     </script>    </body>  </html> 

i know simple, me ending missing small detail!

various sources have been used including question , mdn example

so thank beforehand answers, , have contributed expanding understanding , awareness of topic.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -