title: How to save renderedBuffer as an audio file
body: <p>I am using the web audio api's offlineAudioContext to render an audio file with a different playback speed. When I do this the altered audio is held in the renderedBuffer. </p>
  
  <p>I am wondering how I can download the audio held in the renderedBuffer?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>// define online and offline audio context
  var audioCtx = new AudioContext();
  var offlineCtx = new OfflineAudioContext(2,44100*40,44100);
  source = offlineCtx.createBufferSource();
  // define variables
  var pre = document.querySelector('pre');
  var myScript = document.querySelector('script');
  var play = document.querySelector('.play');
  var stop = document.querySelector('.stop');
  // use XHR to load an audio track, and
  // decodeAudioData to decode it and stick it in a buffer.
  // Then we put the buffer into the source
  function getData() {
  request = new XMLHttpRequest();
  request.open('GET', 'sound.mp4', true);
  request.responseType = 'arraybuffer';
  request.onload = function() {
  var audioData = request.response;
  audioCtx.decodeAudioData(audioData, function(buffer) {
    myBuffer = buffer;
    source.buffer = myBuffer;
    source.playbackRate.value = 0.50;
    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();
      }
    }).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();
  // dump script to pre element
  pre.innerHTML = myScript.innerHTML;
  </code></pre>