6

I am using the Web audio API to stream my mic input into the speakers, so I can hear myself talk through them:

var aCtx = new AudioContext();
navigator.mediaDevices.getUserMedia({audio: true}).then(function (stream) {
     var microphone = aCtx.createMediaStreamSource(stream);
     microphone.connect(aCtx.destination);
})

It works fine, but whenever I keep a steady long voice input, it seems like the output gain drops after a couple of seconds.

I have followed cwilso's advice and added the echo cancellation constraint. But the results are still the same.

Here's a Fiddle: https://jsfiddle.net/hcrgL9eg/

Help would be appreciated.

Niko
  • 369
  • 1
  • 3
  • 14
  • your elongated voice is triggering a noise cancellation filter as it is most probably being identified as background noise and is ("intelligently") being attenuated by the plugin itself. – Bekim Bacaj Jan 26 '17 at 22:56
  • Yes but some solution must be applicable using the right constraint. Can't seem to make it work at the moment. – Niko Jan 27 '17 at 00:15
  • @Nim, you are not applying the same constraints as in jib's answer. The constraint format you specified is out of date. Also, jib used adapter.js polyfill, not sure it is required but could be. – Kaiido Jan 27 '17 at 00:37
  • @Kaiido Thank you, I didn't know it was outdated. I've updated the Fiddle and added the adapter.js library. Still the same result I'm afraid.. – Niko Jan 27 '17 at 00:49
  • @Nim, what version of chrome are you running ? On mine (56.0.2924.76 (64-bit) on osX) it does work perfectly, even with all flags set off. (got a great Larsen on my laptop in 2sec...) Maybe you also have an hardware noise cancellation ? What's your mic ? – Kaiido Jan 27 '17 at 05:02
  • @Nim, I used your updated fiddle with jib's answer's constraints and adapter.js – Kaiido Jan 27 '17 at 05:39
  • @Kaiido Ok great I'll update my code then just in case. What did you mean when you mentioned that all the flags were set off? (I tried to edit my reply to you but deleted it by mistake..) – Niko Jan 27 '17 at 05:44
  • I was talking about `about:flags` page (just type it in your address bar). I usually have some experimental technologies turned on in my browsers, so I did reset it to ensure that it was not some of these that could have interfered with default behavior. – Kaiido Jan 27 '17 at 05:48
  • Ah ok makes sense. I only used to activate panels when it was still available. Anyway thank you very much for letting me know that the issue is probably with my hardware. – Niko Jan 27 '17 at 05:50

1 Answers1

5

Yeah, you're hitting "auto gain control". There are a bunch of features on audio input that are on by default (echo cancellation, AGC, noise reduction). Take a look at Disabling Auto Gain Conctrol with WebRTC App; it's the same solution.

Community
  • 1
  • 1
cwilso
  • 13,610
  • 1
  • 30
  • 35