gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:02:06 26 4
gpt4 key购买 nike

我一整天都被这个问题困扰了。尝试从 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com