分析声音流而不复制它 [英] Analyze sound stream without duplicating it

查看:54
本文介绍了分析声音流而不复制它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过WebRTC获得的音频流.我想对其进行分析,并结合以下代码以直观地显示垃圾箱.

I have an audio stream that I'm obtaining via WebRTC. I want to analyze it, and put together the following code to visually show the bins.

<div id="bins">
</div>
<style>
#bins {
    position: fixed;
    top: 20%;
    width: 100%;
    height: 40%;
    -webkit-transition: 0.1s ease all;
}

.bin {
    background-color: blue;
    height: 100%;
    width: 2px;
    float: left;
}

</style>
<script>
function mediaAnalyze () {
    var audio = webrtc.localStreams[0];
    audioCtx = new AudioContext();
    analyzer = audioCtx.createAnalyser();
    source = audioCtx.createMediaStreamSource(audio);
    source.connect(analyzer);
    analyzer.connect(audioCtx.destination);
    analyzer.fftSize = 128;

    var frequencyData = new Uint8Array(analyzer.frequencyBinCount);

    var bins = [];
    frequencyData.forEach(function(e) {
        var e = document.createElement('div');
        e.classList.add('bin');
        document.getElementById('bins').appendChild(e);
        bins.push(e);
    });
    function renderFrame() {
        analyzer.getByteFrequencyData(frequencyData);
        frequencyData.forEach(function (data, index) {
            bins[index].style.height = ((data * 100) / 256) + "%";
        });
        requestAnimationFrame(renderFrame);
    }
    renderFrame();
};
mediaAnalyze();
</script>

分析仪可以按预期工作,但激活后会听到反馈.我猜这是由于我正在创建的AudioContext.如何在保持原始音频启用的情况下禁用重复的音频/反馈(因为我需要通过WebRTC传输音频/反馈)?

The analyzer works as expected, except that I'm hearing feedback as a result of activating it. I'm guessing it's due to the AudioContext I'm creating. How can I disable duplicate audio/feedback while still keeping the original enabled (since I need to transmit it over WebRTC)?

推荐答案

不要将分析器连接到目标.只是评论

don't connect analyser to destination. just comment

//analyzer.connect(audioCtx.destination);

它应该停止反馈

这篇关于分析声音流而不复制它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆