28

I am trying to implement a webrtc-based chat room. And I encountered the following problems in laptop. Without connecting to any other peer, just use getUserMedia(), I can get local video stream.

When I unmuted the <video>, echo happened.

Then I wear headphones, and found there is a continued noise. And I can hear my voice clearly.

I tried to turn down the volume, but it doesn't work.

Thanks in advance.

Matvey Andreyev
  • 1,021
  • 10
  • 21
Zhenguo Yang
  • 3,800
  • 5
  • 18
  • 22

3 Answers3

72

Make sure that you are muting the local <video> element if you have it in the DOM:

<video id="vid1" autoplay="true" muted="muted"></video>

See this post on the discuss-webrtc mailing list for more details and the WebRTC samples.

tomtheengineer
  • 4,127
  • 1
  • 17
  • 15
  • 1
    If you mute it, it won't capture any sound, will it? – Ronen Festinger Nov 15 '14 at 10:32
  • 9
    The stream will still capture sound even if the local playback element is muted. Muting the element in the DOM will just mute local playback. To mute the outgoing audio stream itself, you'll want to do localMediaStream.getAudioStreams()[0].enabled = false or localMediaStream.getVideoStreams()[0].enabled = false to keep the sound going but disable the video stream. This assumes you saved the media stream somewhere in your onaddstream() callback. – Benjamin Nolan Dec 24 '14 at 02:26
  • Is there a way to remove the echo without losing the sound? – DNM Jan 22 '18 at 07:38
  • @DNM, you won't loose sound with this mute. – Jitendra Pancholi Nov 12 '18 at 09:50
  • Thank You.. This answer saved me. – hithard Apr 13 '20 at 19:53
  • Very helpful, thank you. This fixed it, and @BenjaminNolan explaining that if it's muted you don't lose the audio from the recording was also helpful. Thanks y'all! – Sara Inés Calderón Jun 30 '22 at 14:12
5

Do the followings:

1) In localVideo do the this:

localVideo.volume = 0;

localVideo.muted = 0;

2) Do same for the remoteVideo also:

remoteVideo.volume = 0;

remoteVideo.muted = 0;

ArunDhwaj IIITH
  • 3,833
  • 1
  • 24
  • 14
  • 4
    `muted` attribute didn't help, maybe because of Angular 4 which I use. But this works perfectly `document.getElementById('yourVideo').volume = 0` – Vincente Feb 28 '19 at 14:15
-9

To resolve noise related issue, you should set autoplay=false for localstream.

  • 3
    Could you please elaborate more your answer adding a little more description about the solution you provide? – abarisone Apr 24 '15 at 13:54
  • 1
    autoplay=false just not allow the video to be played automatically. It doesn't have anything to do with audio. – sagar Sep 30 '19 at 08:28