I have a project where I am transmitting audio using Peerjs, A lot of the audio quality has been lost after it has been transferred through peerjs. A good example is stereo audio, the source audio is stereo but after it has been transferred through peerjs it becomes mono. I want to make the audio as high quality as possible. This is the current code that I am using to start the call.
var options = {
'constraints': {
'mandatory': {
'OfferToReceiveAudio': true,
'OfferToReceiveVideo': false
},
offerToReceiveAudio: 1,
offerToReceiveVideo: 0,
}
}
const call = peer.call(data2[1], stream, options);
In the peerjs documentation is says you can include sdpTransform in the options to improve audio quality and I was wondering how I would do that or if anyone had documentation.
I learned that peerjs uses sdp (Session Description Protocol) https://developer.mozilla.org/en-US/docs/Glossary/SDP
var options = {
'constraints': {
'mandatory': {
'OfferToReceiveAudio': true,
'OfferToReceiveVideo': false
},
offerToReceiveAudio: 1,
offerToReceiveVideo: 0,
},
'sdpTransform': (sdp) => {
return sdp;
}
}
By adding in 'sdpTransform' to the options you are able to modify it allowing for the quality of the transmitted audio to be changed. I followed this document which documents the SDP of the OPUS audio codec, from what I have seen peerjs most commonly uses OPUS. https://www.rfc-editor.org/rfc/rfc7587.html
var options = {
'constraints': {
'mandatory': {
'OfferToReceiveAudio': true,
'OfferToReceiveVideo': false
},
offerToReceiveAudio: 1,
offerToReceiveVideo: 0,
},
'sdpTransform': (test) => {
return test.replace("a=fmtp:111 minptime=10;useinbandfec=1","a=fmtp:111 ptime=5;useinbandfec=1;stereo=1;maxplaybackrate=48000;maxaveragebitrat=128000;sprop-stereo=1");
}
}