如何在 webrtc 中增加麦克风增益 [英] How to increase mic gain in webrtc

查看:79
本文介绍了如何在 webrtc 中增加麦克风增益的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在安卓手机(护士用)和平板电脑(病人用)上运行的 webrtc 应用程序.基本上,我已经实现了一个远程助理系统,护士可以通过该系统进行 webrtc 呼叫并听到(仅音频流)患者方面发生的事情.由于平板电脑安装在墙上,因此病床通常距离较远.我想在 webrtc/android 端增加麦克风增益,这样我甚至可以听到低电平的声音.我试图在谷歌上找到线索,但找不到任何有趣的东西.有人能给我提示我将如何提高麦克风灵敏度吗?

I have webrtc application which running on android phone(for Nurses) and tablet(for patients). Basically i have implement a remote assistant system by which nurses can make webrtc call and hear(only audio stream) that whats going on in patient side. As tablet are mounted on wall and patient bed are normally little bit on distance. I want to increase the mic gain either in webrtc/android side so that i can hear even a low level sound. I try to find a clue on google but unable to find anything interesting. Can someone give me hint how i would increase the microphone sensitivity ?

------------------------示例代码---------------------

------------------------ sample code---------------------

 function getLocalStream(successCallback) {
    if (localStream && successCallback) {
        successCallback(localStream);
        return;
    }
    navigator.getUserMedia(streamOptions, function (str) {
        var stream= modifyGain(str);

        uiHandler("peer.call.localstream", {payload: stream});
        localStream = stream;
        if (successCallback) {
            successCallback(stream);
        }
    }, function (err) {
        uiHandler("status.error", {payload: "Failed to access local camera", error: err});
    });
}

function modifyGain (stream){
    var audioTrack = stream.getAudioTracks()[0];
    var ctx = new AudioContext();
    var src = ctx.createMediaStreamSource(stream);
    var dst = ctx.createMediaStreamDestination();
    var gainNode = ctx.createGain();
    gainNode.gain.value = 50;
    [src, gainNode, dst].reduce( function(a, b) { return a && a.connect(b) });
    stream.removeTrack(audioTrack);
    var newAudioTrack = dst.stream.getAudioTracks()[0];

    stream.addTrack(newAudioTrack);
    return stream;
};

在调试中,我发现了以前和新音轨的区别:这是我从本地流获得的原始音轨:

In debug i have found the difference in previous and new audio track: This is original audio track which i get from localstream:

enabled: true
id: "8e4363c2-f1c8-44ec-9bed-f3414f3b943a"
kind: "audio"
label: "Default"
muted: false
onended: null
onmute: null
onunmute: null
readyState: "live"

这是一个新的音轨,它得到 dst.stream.getAudioTracks()[0];

This is a new audio track which get dst.stream.getAudioTracks()[0];

enabled: true
id: "cc0c4293-a606-407e-9adb-4caddaa32583"
 kind: "audio"
label: "MediaStreamAudioDestinationNode"
muted: false
onended: null
onmute: null
onunmute: null
readyState: "live"

id 和 label 对播放流有影响吗?

Is id and label matter to play stream ?

推荐答案

我不知道实际的硬件麦克风是否可以控制,但是您可以通过使用 WebAudio 处理来增加输入信号的增益.

I don't know if the actual hardware mic can be controlled, but you can increase the gain of the input signal by processing it with WebAudio.

试试这个(在 Chrome 中使用 https fiddle):

Try this (use https fiddle in Chrome):

navigator.mediaDevices.getUserMedia({audio: true})
  .then(stream => audio.srcObject = modifyGain(stream, 2.5))
  .catch(e => console.log(e));

var modifyGain = (stream, gainValue) => {
  var ctx = new AudioContext();
  var src = ctx.createMediaStreamSource(stream);
  var dst = ctx.createMediaStreamDestination();
  var gainNode = ctx.createGain();
  gainNode.gain.value = gainValue;
  [src, gainNode, dst].reduce((a, b) => a && a.connect(b));
  return dst.stream;
};

<audio id="audio" controls autoplay></audio>

某些浏览器 (Firefox) 也有 mozAutoGainControl,您可以尝试打开.

Some browsers (Firefox) also have a mozAutoGainControl you could try turning on.

这篇关于如何在 webrtc 中增加麦克风增益的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆