Skip to content

Instantly share code, notes, and snippets.

@Dimon70007
Last active September 13, 2024 22:47
Show Gist options
  • Save Dimon70007/83c2047f66dd44a47dc8bc8f58afb29c to your computer and use it in GitHub Desktop.
Save Dimon70007/83c2047f66dd44a47dc8bc8f58afb29c to your computer and use it in GitHub Desktop.
webrtc - how to remove comfort noise from audio and disable audio processing

That has removed comfort noise from audio and disabled audio processing

const removeComfortNoiseFromSdp = (sdp: sdpTransform.SessionDescription): sdpTransform.SessionDescription => {
  const audioMedias = sdp.media.filter(m => m.type === 'audio')
  const audioMedia = audioMedias[0]
  if (!audioMedia) {
    return sdp // no audio media
  }
  const whitelistedRtps = audioMedia.rtp.filter(rtp => {
    const codec = `${rtp.codec}`.toLowerCase()
    return codec !== 'cn'
  })
  const whitelistedPayloads = whitelistedRtps.map(rtp => rtp.payload)
  audioMedia.rtp = whitelistedRtps
  audioMedia.payloads = whitelistedPayloads.join(' ')
  audioMedia.fmtp = audioMedia.fmtp.map(fmtp => {
    return {
      ...fmtp,
      config: `${fmtp.config}`.replace('useinbandfec=1;', 'useinbandfec=1; stereo=1; maxaveragebitrate=510000'),
    }
  })
  return sdp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment