javascript - 使用 AnalyserNode 和 ChannelSplitter 获取 L/R 数据

标签 javascript html web-audio-api

我一整天都被这个问题困扰了。尝试从 getUserMedia 中分离源并分别可视化左 channel 和右 channel 。无论我做什么,每个可视化工具都停留在单声道状态。我使用的源是立体声(如果我在 Windows 中收听它,它显然是立体声)。复制所需的最低限度。

        navigator.getUserMedia({audio: true}, analyse, function(e) {
                    alert('Error getting audio');
                    console.log(e);
                });
        }

        function analyse(stream){
            window.stream = stream;

            var input = audioContext.createMediaStreamSource(stream);
                splitter = audioContext.createChannelSplitter(2),
                lAnalyser = audioContext.createAnalyser(),
                rAnalyser = audioContext.createAnalyser();
            input.connect(splitter);
            splitter.connect(lAnalyser, 0, 0);
            splitter.connect(rAnalyser, 1, 0);
            var lArray = new Uint8Array(lAnalyser.frequencyBinCount),
                rArray = new Uint8Array(rAnalyser.frequencyBinCount);
            updateAnalyser()
            function updateAnalyser(){
                requestAnimationFrame(updateAnalyser);
                lAnalyser.getByteFrequencyData(lArray);
                rAnalyser.getByteFrequencyData(rArray);
            }
       }

即使我将左声道或右声道静音,lArray 和 rArray 也将是相同的。难道我做错了什么?我也尝试过输入->分离器->左合并/右合并->左分析器/右分析器。

http://www.smartjava.org/content/exploring-html5-web-audio-visualizing-sound 是我能找到的最相似的东西,但它不使用用户输入并处理音频缓冲区。

最佳答案

根据https://code.google.com/p/chromium/issues/detail?id=387737

The behaviour is expected. In M37, we moved the audio processing from peer connection to getUserMedia, and the audio processing is turned on by default if you do no specify "echoCancellation : false" in the getUserMedia constraints, since the audio processing only support mono, we have to down sample the audio to mono before passing the data for processing.

If you want to avoid the down sampling, passing a constraint to getUserMedia, for example: var constraints = {audio: { mandatory: { echoCancellation : false, googAudioMirroring: true } }}; getUserMedia(constraints, gotStream, gotStreamFailed);

将约束设置为 {audio: { permanent: { echoCancellation: false}} 会停止输入缩混。

关于javascript - 使用 AnalyserNode 和 ChannelSplitter 获取 L/R 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31697427/

相关文章:

html - 希望文本元素在单元格顶部对齐

javascript - 使用 DASH 流式传输多轨音频

javascript - WebAudio API 更改源之一的音量

javascript - 尝试将 jquery 和 jquery-ujs 与 Browserify 一起使用,但出现 Uncaught ReferenceError : jQuery is not defined

javascript - 如何向 Google map 添加用户位置标记?

JavaScript 命名空间未捕获类型错误

javascript - 在表单中添加行,只有第一个信息按钮打开

javascript - 每个客户端的 meteor 同步内容

javascript - Chrome 控制台中显示 HTML 多行 "style=-lns..."

javascript - 网络音频 Api 输出