title: Reducing sample rate of a Web Audio spectrum analyzer using mic input
body: <p>I'm using the Web Audio API to create a simple spectrum analyzer using the computer microphone as the input signal. The basic functionality of my current implementation works fine, using the default sampling rate (usually 48KHz, but could be 44.1KHz depending on the browser).</p>
  
  <p>For some applications, I would like to use a lower sampling rate (~8KHz) for the FFT.</p>
  
  <p>It looks like the Web Audio API is adding support to customize the sample rate, currently only available on FireFox (<a href="https://developer.mozilla.org/en-US/docs/Web/API/AudioContextOptions/sampleRate" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/AudioContextOptions/sampleRate</a>).</p>
  
  <p>Adding sample rate to the context constructor:</p>
  
  <pre><code>// create AudioContext object named 'audioCtx'
  var audioCtx = new (AudioContext || webkitAudioContext)({sampleRate: 8000,});
  console.log(audioCtx.sampleRate)
  </code></pre>
  
  <p>The console outputs '8000' (in FireFox), so it appears to be working up to this point.</p>
  
  <p>The microphone is turned on by the user using a pull-down menu.  This is the function servicing that pull-down:</p>
  
  <pre><code>var microphone;
  function getMicInputState()
  {
    let selectedValue = document.getElementById("micOffOn").value;
    if (selectedValue === "on") {
      navigator.mediaDevices.getUserMedia({audio: true})
        .then(stream =&gt; {
          microphone = audioCtx.createMediaStreamSource(stream);
          microphone.connect(analyserNode);
        })
        .catch(err =&gt; { alert("Microphone is required."); });
    } else {
      microphone.disconnect();
    }
  }
  </code></pre>
  
  <p>In FireFox, using the pulldown to activate the microphone displays a popup requesting access to the microphone (as normally expected). After clicking to allow the microphone, the console displays: </p>
  
  <blockquote>
    <p>"Connecting AudioNodes from AudioContexts with different sample-rate is currently not supported". </p>
  </blockquote>
  
  <p>The display of the spectrum analyzer remains blank.</p>
  
  <p>Any ideas how to overcome this error?  If we can get past this, any guidance on how to specify sampleRate when the user's soundcard sampling rate is unknown?</p>