Getting access to the user's microphone through navigator.getUserMedia
is pretty easy. But what if I'm using a mobile browser and want to pick up audio from a distance, like with a "speakerphone" mode?
通过导航器访问用户的麦克风。getUserMedia是非常容易的。但如果我使用的是移动浏览器,想要从远处接收音频,比如使用“扬声器”模式呢?
How would I go about achieving this? There seem to be native apps that can achieve this, but what about Web Audio?
我该如何实现这个目标呢?似乎有一些本地应用可以实现这一点,但是Web音频呢?
The purpose of this is for sending messages between devices using DTMF. I have already achieved this with my laptop because its microphone can record surrounding audio from a great distance, but any mobile phone I have access to seems to only record audio near the "mouthpiece" and so I have to hold the phone extremely close to the source speaker for even a slight chance of having a message received. This defeats the purpose unless I can get the mobile microphone to pick up audio from a distance.
这是为了在使用DTMF的设备之间发送消息。我用笔记本电脑,因为它已经达到了这个麦克风可以记录周围的声音从很远的地方,但任何手机我访问似乎只记录音频附近的“喉舌”,所以我必须持有手机非常接近源发言人甚至一点点的机会有一个消息收到。除非我能让移动麦克风从远处接收音频,否则这就违背了目的。
EDIT: By distance, I mean greater than a few feet, as opposed to mere centimeters. Ambient sounds, as opposed to sound localized next to the microphone.
编辑:我指的是距离,大于几英尺,而不是厘米。周围的声音,而不是局限在麦克风旁边的声音。
3 个解决方案
#1
2
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.
不能这样做,因为它与设备的硬件直接相关。如果设备硬件(麦克风)无法接收到几米以外的声音,那么就没有办法了。
#2
1
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.
在更新版本的Chrome浏览器上,导航器。mediaDevices有一个名为enumerateDevices的函数,可以用来列出可用的硬件设备,包括麦克风。事实证明,它确实会返回我Android手机上的“扬声器”设备。因此,如果您有一个设备,您怀疑扬声器没有设置为默认的浏览器麦克风,并且您(或您的用户)在Chrome版本47或以上,您可以使用enumerateDevices返回的设备id来指定一个特定的麦克风。
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
.
因此,如果您的用户为特定的麦克风设备在select元素中选择一个选项,您将获取该设备的ID并将其传递给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.
注意,在本文中,enumerateDevices API仅在Chrome上可用。在任何其他浏览器或web视图中,这可能都不起作用。
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.
如果麦克风的音量对您的应用程序来说太低,您可以通过为您的AudioContext创建一个gainNode来增加它。
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.
或者,如果你处理的是原始样本,你可以把每个样本乘以一个数字,然后把它们传递给你要处理的函数。
#3
0
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.
两年前,我实现了一个在移动web浏览器上工作的webrtc(使用谷歌示例),声音以环境级别捕获。我并没有对谷歌库进行深入的代码分析,但是也许你可以从这里开始。
#1
2
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.
不能这样做,因为它与设备的硬件直接相关。如果设备硬件(麦克风)无法接收到几米以外的声音,那么就没有办法了。
#2
1
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.
在更新版本的Chrome浏览器上,导航器。mediaDevices有一个名为enumerateDevices的函数,可以用来列出可用的硬件设备,包括麦克风。事实证明,它确实会返回我Android手机上的“扬声器”设备。因此,如果您有一个设备,您怀疑扬声器没有设置为默认的浏览器麦克风,并且您(或您的用户)在Chrome版本47或以上,您可以使用enumerateDevices返回的设备id来指定一个特定的麦克风。
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
.
因此,如果您的用户为特定的麦克风设备在select元素中选择一个选项,您将获取该设备的ID并将其传递给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.
注意,在本文中,enumerateDevices API仅在Chrome上可用。在任何其他浏览器或web视图中,这可能都不起作用。
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.
如果麦克风的音量对您的应用程序来说太低,您可以通过为您的AudioContext创建一个gainNode来增加它。
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.
或者,如果你处理的是原始样本,你可以把每个样本乘以一个数字,然后把它们传递给你要处理的函数。
#3
0
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.
两年前,我实现了一个在移动web浏览器上工作的webrtc(使用谷歌示例),声音以环境级别捕获。我并没有对谷歌库进行深入的代码分析,但是也许你可以从这里开始。