我有一个我通过WebRTC获得的音频流。我想分析它,并将以下代码放在一起以直观地显示垃圾箱。
<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传输)?