简体   繁体   English

WebRTC:获取mediaStream *的音频级别,而不播放音频

[英]WebRTC: Get audio level of a mediaStream *without* playing back the audio

I'm looking to get the microphone activity level of a WebRTC MediaStream. 我希望获得WebRTC MediaStream的麦克风活动级别。 However, I need to get this information without playing back the microphone to the user (otherwise there will be the loopback effect). 但是,我需要在向用户播放麦克风的情况下获取此信息(否则会出现环回效果)。

The answer in Microphone activity level of WebRTC MediaStream relies on the audio being played back to the user. WebRTC MediaStream的麦克风活动级别中的答案依赖于播放给用户的音频。 How can I do this, without playing back the microphone? 如何在不播放麦克风的情况下执行此操作?

Take a look at createGain method . 看看createGain方法 It allows you to set stream's volume. 它允许您设置流的音量。

Here is my (simplified) example that I use in my project: 这是我在项目中使用的(简化)示例:

navigator.getUserMedia({audio: true, video: true}, function(stream) {
    var audioContext = new AudioContext; //or webkitAudioContext
    var source = audioContext.createMediaStreamSource(stream);

    var volume = audioContext.createGain();
    source.connect(volume);
    volume.connect(audioContext.destination);
    volume.gain.value = 0;  //turn off the speakers

    //further manipulations with source
}, function(err) {
    console.log('error', err);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM