Web Audio: How can I get a mobile microphone to pick up audio from a distance? Web Audio: How can I get a mobile microphone to pick up audio from a distance? google-chrome google-chrome

Web Audio: How can I get a mobile microphone to pick up audio from a distance?


I am answering my own question here. Thanks to everyone who helped out, though none of the actual answers posted here were satisfactory, IMO.

On newer versions of Chrome, navigator.mediaDevices has a function called enumerateDevices which can be used to list available hardware devices, including microphones. As it turns out, this does return a "speakerphone" device on my Android phone. So, if you have a device where you suspect that speakerphone isn't set as the default browser microphone, and you(or your user) is on Chrome version 47 or above, you can use the device IDs returned by enumerateDevices to specify a specific microphone.

So, if your user chooses an option in a select element for a specific microphone device, you would take the ID for that device and pass it to getUserMedia.

navigator.getUserMedia({ audio: {deviceId: {exact: <insert device uuid here>}} }, callback)

Note that, as of this posting, the enumerateDevices API is only available on Chrome. In any other browser or web view, this probably won't work.

If the volume of the microphone happens to be too low for your application, you can increase it by creating a gainNode for your AudioContext.

volume     = context.createGain()volume.gain.value = 3 // raises the volume to 300%audioInput = context.createMediaStreamSource(e)audioInput.connect(volume)

Or, if you are dealing with raw samples, you can literally multiply each sample by a number before passing them to whatever function you are using to process them.


This cannot be done as it's directly related to the hardware of the device. If the device hardware (microphone) cannot pick up sounds from meters away, then there's nothing that can be done.


Two years ago, I implemented a webrtc (using google example) that works on mobile web browser, and the sound is captured with ambience levels. I really didn't a deep code analysis of google libraries but maybe you can start here.