title: How do I get buffers/raw data from AudioContext?
body: <p>I am trying to record and save sound clips from the user microphone using the <code>GetUserMedia()</code> and <code>AudioContext</code> APIs. </p>
  
  <p>I have been able to do this with the <code>MediaRecorder</code> API, but unfortunately, that's not supported by Safari/iOS, so I would like to do this with just the <code>AudioContext</code> API and the buffer that comes from that.  </p>
  
  <p>I got things partially working with <a href="https://developers.google.com/web/fundamentals/media/recording-audio/" rel="nofollow noreferrer">this tutorial from Google Web fundamentals</a>, but I can't figure out how to do the following steps they suggest.  </p>
  
  <pre><code>var handleSuccess = function(stream) {
      var context = new AudioContext();
      var source = context.createMediaStreamSource(stream);
      var processor = context.createScriptProcessor(1024, 1, 1);
  
      source.connect(processor);
      processor.connect(context.destination);
  
      processor.onaudioprocess = function(e) {
          // ******
          // TUTORIAL SUGGESTS: Do something with the data, i.e Convert this to WAV 
          // ******
          // I ASK: How can I get this data in a buffer and then convert it to WAV etc.??
          // *****
          console.log(e.inputBuffer);
      };
  };
  
  navigator.mediaDevices.getUserMedia({ audio: true, video: false })
      .then(handleSuccess);
  </code></pre>
  
  <p>As the tutorial says:</p>
  
  <blockquote>
    <p>The data that is held in the buffers is the raw data from the
    microphone and you have a number of options with what you can do with
    the data:</p>
    
    <ul>
    <li>Upload it straight to the server </li>
    <li>Store it locally  </li>
    <li>Convert to a dedicated file format, such as WAV, and then save it to your servers or locally  </li>
    </ul>
  </blockquote>
  
  <p>I could do all this, but <strong>I can't figure out how to get the audio buffer once I stop the context</strong>. </p>
  
  <p>With <code>MediaRecorder</code> you can do something like this:</p>
  
  <pre><code>mediaRecorder.ondataavailable = function(e) {
      chunks.push(e.data);
  }
  </code></pre>
  
  <p>And then when you're done recording, you have a buffer in <code>chunks</code>. There must be a way to this, as suggested by the tutorial, but I can't find the <code>data</code> to push into the buffer in the first code example.</p>
  
  <p>Once I get the audio buffer I could <a href="https://www.npmjs.com/package/audiobuffer-to-wav" rel="nofollow noreferrer">convert it to WAV</a> and make it into a blob etc.  </p>
  
  <p>Can anyone help me with this? (I don't want to use the <code>MediaRecorder</code> API)</p>