Web audio API and multiple inputs mic device

梦想的初衷 提交于 2019-12-10 17:22:17

问题


I have an audio device with 4 inputs microphones..

Someone knows if i can use all these inputs with Web audio API ?

Thanks !


回答1:


It should work by calling getUserMedia four times, choosing a different device each time, and using createMediaStreamSource four times, although I haven't tested.




回答2:


yes,you can list all input devices and select one to use.

<html><body>

<select id="devices_list"></select>
<script>
function devices_list(){
        var handleMediaSourcesList = function(list){
            for(i=0;i<list.length;i++){
                var device= list[i];
                if(device.kind == 'audioinput') {
                    document.querySelector('#devices_list').options.add(new Option(device.label ,device.deviceId));
                }
            }

        }
        if (navigator["mediaDevices"] && navigator["mediaDevices"]["enumerateDevices"])
            {
                navigator["mediaDevices"]["enumerateDevices"]().then(handleMediaSourcesList);
            }
            // Old style API
            else if (window["MediaStreamTrack"] && window["MediaStreamTrack"]["getSources"])
            {
                window["MediaStreamTrack"]["getSources"](handleMediaSourcesList);
            }
}

function usemic(){

    navigator.getUserMedia ({
      "audio":{
            "optional": [{
            "sourceId": document.querySelector('#devices_list').value
             }]
        }}, function (stream) {
            //...some code to use stream from mic
        },function(err){
            debuginfo('getMedia ERR:'+err.message );
        });
}
</script>
</body></html>


来源:https://stackoverflow.com/questions/27433904/web-audio-api-and-multiple-inputs-mic-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!