title: Web Audio API downloading encoded audio
body: <p>I am trying to decode an audio file, apply an effect, then encode it again to .WAV format so the user can save the file back to their computer.</p>
  
  <p>At the moment when I press the "Play" button the sound plays as it should, but no download box is popping up, for the user to download the encoded file. </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  
    &lt;head&gt;
      &lt;meta charset="utf-8"/&gt;
  
      &lt;title&gt;offlineAudioContext example&lt;/title&gt;
  
      &lt;script src="recorder.js"&gt;&lt;/script&gt;
  
    &lt;/head&gt;
  
    &lt;body&gt;
  
      &lt;button class="play"&gt;Play&lt;/button&gt;
  
     &lt;script&gt;
  
  // define online and 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 to decode audio then 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 the new worker
          worker.postMessage({
          command: 'init',
          config: {
          sampleRate: 44100
  
      }
    });
  
  
    // callback for `exportWAV`
  
  
    // send the channel data from our buffer to the worker
      worker.postMessage({
          command: 'record',
          buffer: [
              buffer.getChannelData(0),
              buffer.getChannelData(1)
          ]
  });
  
    // ask the worker for a 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: The promise should reject when startRendering is called a second time on an OfflineAudioContext
        });
      });
    }
  
    request.send();
  
  }
  
  // Run getData to start the process off
  
  getData();
  
  
    &lt;/script&gt;
  
    &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>I know it is probably something very simple, it often is with me I always ending up missing a small detail!</p>
  
  <p>Various sources have been used including another <a href="https://stackoverflow.com/questions/22560413/html5-web-audio-convert-audio-buffer-into-wav-file">question</a> and <a href="http://mdn.github.io/offline-audio-context-promise/" rel="nofollow noreferrer">MDN example</a></p>
  
  <p>So thank you beforehand for any answers, and those who have already contributed to expanding understanding and awareness of this topic. </p>