Re: Two Audio Inputs Per User

174 views
Skip to first unread message
Message has been deleted

guest271314

unread,
Mar 5, 2023, 12:47:23 PM3/5/23
to discuss-webrtc
You can utilize Web Audio API MediaStreamAudioDestinationNode to merge multiple audio tracks into one MediaStreamTrack and MediaStreamAudioSourceNode to output that MediaStream. See https://groups.google.com/a/chromium.org/g/chromium-dev/c/ay7xRHxfC8U.

On Sunday, March 5, 2023 at 8:08:44 AM UTC-8 Paul Doyle wrote:
Hi all,

I'm very new to WebRTC so any help would be greatly appreciated.

I have a basic peer to peer video call set up and working fine, but my main goal is for each user to be able to add two audio inputs to the connection (usb microphone, guitar signal from audio interface). So far I've been able to get either one or the other signal working fine, I've also tried using .getMediaDisplay so that both microphone and screen audio can be heard as a work around, but again only one audio track will be heard.

Is WebRTC even capable of having two tracks of audio, or must I find a way to first merge the audio inputs then add the single track to the connection? Thanks in advanced, code snipped for setting up sources below.

  //Get user's camera and audio
    const localStream = await navigator.mediaDevices.getUserMedia({
      video: true,
      audio: true,
    });
    const remoteStream = new MediaStream();

    //Add the local tracks to the WebRTC peer connection
    localStream.getTracks().forEach((track) => {
      pc.addTrack(track, localStream);
    });

    //Get desktop tracks
    const desktopStream = await navigator.mediaDevices.getDisplayMedia({
      video: true,
      audio: true,
    });

    //Add the desktop tracks to the local WebRTC peer connection
    desktopStream.getTracks().forEach((track) => {
      pc.addTrack(track, localStream);
    });

    //Listen to the onTrack even on the peer conneciton, add tracks to the remote stream
    pc.ontrack = (event) => {
      event.streams[0].getTracks().forEach((track) => {
        remoteStream.addTrack(track);
      });
    };

    localRef.current.srcObject = localStream;
    remoteRef.current.srcObject = remoteStream;

    setWebcamActive(true);

Philipp Hancke

unread,
Mar 6, 2023, 3:40:36 AM3/6/23
to discuss...@googlegroups.com
your ontrack handler adds two audio tracks to the same media stream which is unlikely to be supported. Putting them in separate streams
or fixing your local addTrack code not to signal the localStream but the actual desktopStream and then not doing fancy stuff in ontrack but attaching the resulting event.streams[0] to separate audio elements should work.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/fe479c1b-e973-4d8b-b342-89080b08e963n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages