简体   繁体   中英

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. 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. How can I do this, without playing back the microphone?

Take a look at createGain method . 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);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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