1

I just started learning webrtc and I have a problem. The audio quality (I don't care about video) drops after few seconds. At the beginning the quality is perfect but then it drops. I'm in a private network where the only running thing is a raspberry which has an usb audiocard attached and a stream server running, a small switch and a PC where I listen to the stream that comes out of the raspberry. I tried to modify the sdp string (by setting some parameters such as the bandwidth) without success.

Does anybody have an idea?

Thank you very much in advance, David.

1 Answers1

0

The default settings will give you mono audio around 42 kb/s, as it's primarily designed for voice. Here is how to increase the audio quality:

  1. Disable autoGainControl, echoCancellation and noiseSuppression in the getUserMedia() constraints:

    navigator.mediaDevices.getUserMedia({ audio: { autoGainControl: false, channelCount: 2, echoCancellation: false, latency: 0, noiseSuppression: false, sampleRate: 48000, sampleSize: 16, volume: 1.0 } });

  2. Add the stereo and maxaveragebitrate attributes to the SDP:

    let answer = await peer.conn.createAnswer(offerOptions); answer.sdp = answer.sdp.replace('useinbandfec=1', 'useinbandfec=1; stereo=1; maxaveragebitrate=510000'); await peer.conn.setLocalDescription(answer);

This should output a string which looks like this:

a=fmtp:111 minptime=10;useinbandfec=1; stereo=1; maxaveragebitrate=510000

This gives a potential maximum bitrate of 520kb/s for stereo, which is 260kps per channel. Actual bitrate depends on the speed of your network and strength of your signal.

You can read more about the other available attributes at: https://www.rfc-editor.org/rfc/rfc7587

Community
  • 1
  • 1
Kim T
  • 5,770
  • 1
  • 52
  • 79