使用AudioContext将麦克风音频流式传输到扬声器

时间:2013-06-21 15:45:08

标签: javascript audio-streaming html5-audio microphone webkitaudiocontext

我觉得Chrome中可能已经发生了一些变化,因为这些功能的演示似乎不再起作用了。我没有发现任何这样的话。这是我的代码:

navigator.getUserMedia = ( navigator.getUserMedia    || navigator.webkitGetUserMedia ||
                           navigator.mozGetUserMedia ||navigator.msGetUserMedia);

var aCtx;
var analyser;
var microphone;
if (navigator.getUserMedia) {
    navigator.getUserMedia({audio: true}, function(stream) {
        aCtx = new webkitAudioContext();
        analyser = aCtx.createAnalyser();
        microphone = aCtx.createMediaStreamSource(stream);
        microphone.connect(analyser);
        analyser.connect(aCtx.destination);
    });
};

我无法通过扬声器播放音频。我希望我的代码不正确,这仍然是可能的。如果我使用音频标签并直接发送它,我可以让它工作但我希望能够为它添加过滤器。

2 个答案:

答案 0 :(得分:0)

你做了一个打字错误。你的第一行应该是

navigator.getUserMedia = ( navigator.getUserMedia    || navigator.webkitGetUserMedia ||
                           navigator.mozGetUserMedia ||navigator.msGetUserMedia);

答案 1 :(得分:0)

看起来我需要将麦克风更改为默认值。它是在显示音频上设置的。enter image description here