Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo and noise in sound webRTC android

Tags:

android

webrtc

I am working on webRTC i am doing live stream between two android devices on local network it is working pretty fine for me except the sound quality issue there is noise and echo in sound. If i use hands-free on one end it gets better but i don't want to use hands-free.

So how can i improve the sound quality, what techniques are there to improve the sound quality. It also said the webRTC has echo cancellation functionality built in if it's than why echo is still there.

like image 859
umerk44 Avatar asked Mar 25 '15 06:03

umerk44


3 Answers

You can try to add special audio constraints when you are creating audio source. It should looks like:

MediaConstraints audioConstraints = new MediaConstraints();
audioConstarints.mandatory.add(new MediaConstraints.KeyValuePair("googNoiseSuppression", "true"));
audioConstarints.mandatory.add(new MediaConstraints.KeyValuePair("googEchoCancellation", "true"));

There are a lot of media constraints related to audio features and I suggest to try different combinations of them, full list can be found here https://chromium.googlesource.com/external/webrtc/+/master/talk/app/webrtc/mediaconstraintsinterface.cc

like image 179
Alexey Osminin Avatar answered Nov 13 '22 20:11

Alexey Osminin


What's happening is that you are playing your own local audio back to yourself. This creates a feedback loop between your microphone and speakers. That's why it kinda sounds better when you have the hands-free device. You can remove the local audio by modifying the stream of getUserMedia():

var constraints = {video: true, audio: true};
getUserMedia(constraints, function(stream){
    var videoOnly = new MediaStream(stream.getVideoTracks());
}, errorHandler);
like image 41
Tony Rizko Avatar answered Nov 13 '22 21:11

Tony Rizko


I guess you are experiencing the Larsen effect, the 2 audio outputs being replayed by both microphones, creating endless audio loops. There is not much you can do against this if both devices are in the same room, but indeed browsers have echo cancellation options you can activate this way (not sure they are by default):

if (window.chrome) {
    audioConstraints = {
        mandatory: {
            echoCancellation: true
        }
    }
} else {
    audioConstraints = {
        echoCancellation: true
    }
}
var constraints = {video: videoConstraints, audio: audioConstraints};
navigator.getUserMedia(constraints, userMediaSuccess, userMediaError);

Also, mute the local video, users obviously don't need it.

like image 2
peveuve Avatar answered Nov 13 '22 20:11

peveuve