muaz-khan / WebRTC-Experiment

WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
https://www.webrtc-experiment.com/
MIT License
11.77k stars 3.95k forks source link

Streaming audio on separate channels #288

Open doctorA opened 10 years ago

doctorA commented 10 years ago

Greetings.

First of all I would like to thank you for all your tutorials, they provide excellent entry point to learn WebRTC for beginners like myself.

Now for the question: Is it possible to set up WebRTC to output certain audio streams to selected sound card channels? For example, I have a 5.1 surround system and I want to output WebRTC audio stream 1 to a certain channel (e.g. central speaker) and to output audio stream 2 to another channel (e.g. back left speaker).

I've found that WebRTC has a internal API called VoeBase, which should provide multichannel support but I am not sure this applies my problem.

Thank you very much for your answer in advance.

Best regards.

muaz-khan commented 10 years ago

A javascript application can invoke navigator.enumerateDevices interface to fetch list of all available audio and/or video output devices. Now, whilst invoking getUserMedia API, such javascritp applications can pass optional sourceId to force output device selection. Chrome is still implementing such kind of interfaces and we can't yet select audio-output device.

navigator.getUserMedia({
    audio: {
        mandatory: {},
        optional: [{
            sourceId: 'audio-output-device-id'
        }]
    }
}, onSuccess, onFailure);

Chrome is also having another boolean optional audio constraint i.e. chromeRenderToAssociatedSink which can be used to force chrome to use single device for both audio input and output. This one works in current stable channels.

navigator.getUserMedia({
    audio: {
        mandatory: {},
        optional: [{
            chromeRenderToAssociatedSink: true
        }]
    }
}, onSuccess, onFailure);

P.S. Sorry I don't having experience with native API.

doctorA commented 10 years ago

Thank you very much for your explanation. One more question though, although multichannel support, as you said, isn't implemented yet, is it possible to at least to specify to which speaker the sound should be outputted?

Consider the following example: we have a stereo sound system, e.g. normal 2.0 system - 2 speakers connected to the standard sound card via 3.5 mm audio jack and I have two audio streams. I want to output one audio stream to the left speaker and another audio stream to the right speaker. Is this possible or does the same limitations apply as with multichannel scenario?

Thanks again for your help.

Best regards.

thanghv55 commented 8 years ago

Hi doctorA, Muazkhan I have the same your question, have you found a solution for this issue? Can you help me?