如何在peer.js中使用sdptransform?

发布于 2025-02-13 20:38:25 字数 1647 浏览 1 评论 0原文

我正在使用Peer.js开发一个为Android开发语音呼叫应用程序。它正在工作,但音频有滞后(大约1-5秒)。因此,我正在寻找修复程序,发现我可以启用dtx音频以减少发送的数据包数量。但是我不知道如何在peer.js中访问和更改sdp对象。这是我的代码,

let audioConstraints = {
    channelCount: 1,
    sampleRate: 16000,
    sampleSize: 8,
    volume: 1,
    latency: 0.003,
    echoCancellation: true,
    noiseSuppression: true,
    autoGainControl: true,
  };

constraints = { audio: audioConstraints, video: false };

let localStream;
//listen for calls
function listen() {
  peer.on("call", (call) => {
    navigator.mediaDevices
      .getUserMedia(constraints)
      .then(function (stream) {
        localVideo.srcObject = stream;
        localStream = stream;
        call.answer(stream);
        call.on("stream", (remoteStream) => {
          Android.onPeerStream();
          remoteVideo.srcObject = remoteStream;
        });
      })
      .catch(function (err) {
        Android.logEvent("getUserMedia error: " + err);
      });
  });
}

//start call
function startCall(otherUserId) {
  navigator.mediaDevices
    .getUserMedia(constraints)
    .then(function (stream) {
      localVideo.srcObject = stream;
      localStream = stream;
      const call = peer.call(otherUserId, stream);
      call.on("stream", (remoteStream) => {
        Android.onPeerStream();
        remoteVideo.srcObject = remoteStream;
      });
    })
    .catch(function (err) {
      Android.logEvent("getUserMedia error: " + err);
    });
}

有人可以在peer.js中分享一个如何访问和修改SDP的工作示例?另外,如何调整audioconstraints在保持体面的语音质量的同时达到低网络滞后?

更新 找到了在PEER.JS中访问SDP的方法,但仍然无法弄清楚如何启用DTX音频。

I am developing a voice call app for android using peer.js. It is working but there is a lag in audio (around 1-5 seconds). So I was searching for a fix and found out that I can enable DTX Audio to reduce the number of packets sent. But I have no idea How to access and change SDP object in peer.js. Here is my code,

let audioConstraints = {
    channelCount: 1,
    sampleRate: 16000,
    sampleSize: 8,
    volume: 1,
    latency: 0.003,
    echoCancellation: true,
    noiseSuppression: true,
    autoGainControl: true,
  };

constraints = { audio: audioConstraints, video: false };

let localStream;
//listen for calls
function listen() {
  peer.on("call", (call) => {
    navigator.mediaDevices
      .getUserMedia(constraints)
      .then(function (stream) {
        localVideo.srcObject = stream;
        localStream = stream;
        call.answer(stream);
        call.on("stream", (remoteStream) => {
          Android.onPeerStream();
          remoteVideo.srcObject = remoteStream;
        });
      })
      .catch(function (err) {
        Android.logEvent("getUserMedia error: " + err);
      });
  });
}

//start call
function startCall(otherUserId) {
  navigator.mediaDevices
    .getUserMedia(constraints)
    .then(function (stream) {
      localVideo.srcObject = stream;
      localStream = stream;
      const call = peer.call(otherUserId, stream);
      call.on("stream", (remoteStream) => {
        Android.onPeerStream();
        remoteVideo.srcObject = remoteStream;
      });
    })
    .catch(function (err) {
      Android.logEvent("getUserMedia error: " + err);
    });
}

could someone please share a working example of how to access and modify SDP in peer.js? Also, how can I tune the audioConstraints to achieve low network lag while keeping decent voice quality?

UPDATE
Found the way to access SDP in peer.js but still can't figure it out how to enable DTX audio.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文