title: How can I separate stereo microphone input channels by Web Audio API javascript
body: <p>I try to separate stereo microphone channels with following javascript and Web Audio API.. but it is not working as I expected.
  The input stereo microphone is designed to separate telephone conversation in ch0(speaking) and ch1(receiving). This stereo microphone is working fine with QuickTime audio recording. speaking and receiving voice are separated to L and R. With Firefox, The speaking and receiving voice are mixed on splitter's channel0. and nothing on channel1. with Chrome, The speaking and receiving voice are mixed and appears on both channel0 and channel1 of splitter. My goal is to separate the speaking voice on channel0 and receiving voice on channel1.
  the function is callbacked when Microphone permission granted in navigator.getUserMedia({audio: true}.</p>
  
  <p>Does anyone have advise?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>Microphone.prototype.onMediaStream = function(stream) {
    var audioTrack=stream.getAudioTracks();
    var audioStreamTrackName = audioTrack[0].label;
    var audioStreamTrackType = audioTrack[0].kind;
    console.log('onMediaStream: getAudioTracks:[0] '+ audioStreamTrackName +' '+ audioStreamTrackType);
    var AudioCtx = window.AudioContext || window.webkitAudioContext;
    var maxdb =-10.0, mindb=-80.0, fft=2048, smoothing =0.8,maxVol=1.0,minVol=0.0;
    if (!AudioCtx)
      throw new Error('AudioContext not available');
    if (!this.audioContext)
     this.audioContext = new AudioCtx();
  // create two analyser
     this.analyser0 = this.audioContext.createAnalyser();
     this.analyser0.fftSize = fft;
     this.analyser0.minDecibels=mindb;
     this.analyser0.maxDecibels=maxdb;
     this.analyser0.smoothingTimeConstant=smoothing;
     this.analyser1 = this.audioContext.createAnalyser();
     this.analyser1.fftSize = fft;
     this.analyser1.minDecibels=mindb;
     this.analyser1.maxDecibels=maxdb;
     this.analyser1.smoothingTimeConstant=smoothing;
     this.splitter = this.audioContext.createChannelSplitter(2);   //2ch splitter Stereo to 2 monoral stream
     this.merger = this.audioContext.createChannelMerger(2);       //2ch marger   two monoral to stereo
     this.gainCh0 = this.audioContext.createGain();
     this.gainCh1 = this.audioContext.createGain();
     this.gainCh0.gain.value = maxVol;    // max 
     this.gainCh1.gain.value = maxVol;    // max
     if (!this.mic) {
      this.mic = this.audioContext.createScriptProcessor(8192,2,2);
     }
     this.mic.onaudioprocess = this._onaudioprocess.bind(this);
     this.stream = stream;
     this.audioInput = this.audioContext.createMediaStreamSource(stream);
  // audio-nodes connections   
     this.audioInput.connect(this.splitter);
     this.splitter.connect(this.gainCh0, 0);     // connect splitter output channel0 to gainCh0
     this.splitter.connect(this.gainCh1, 1);     // connect splitter output channel1 to gainCh
     this.gainCh0.connect(this.merger, 0, 0);    //connect gainCh0 output channel0 to merger input channel0 
     this.gainCh1.connect(this.merger, 0, 1);    //connect gainCh1 output channel0 to merger input channel1 
     this.merger.connect(this.mic);              // connect merger to ScriptProcessor
     this.mic.connect(this.audioContext.destination);
     this.gainCh0.connect(this.analyser0);
     this.gainCh1.connect(this.analyser1);
  // start recording
     this.onStartRecording();
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/5D4hR.png" rel="nofollow noreferrer">firefox web audio debug tool output</a></p>