[英]Record Low Volume Input from Microphone using Web Audio API
I'm trying to figure out how to use the Web Audio API to record low volume input from a mircophone.我试图弄清楚如何使用 Web Audio API 来录制来自麦克风的低音量输入。 So essentially I'm looking to record in low frequencies or decibels that start from 0Hz to around 100Hz.
所以基本上我希望以从 0Hz 到 100Hz 左右的低频或分贝进行录制。
Any help would be appreciated.任何帮助,将不胜感激。 Thanks.
谢谢。
So this is what I've got so far:所以这就是我到目前为止所得到的:
if (!navigator.getUserMedia) {
navigator.getUserMedia = navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
}
navigator.getUserMedia({
audio: true
}, function(stream) {
var ctx = new AudioContext();
var source = ctx.createMediaStreamSource(stream);
var gainNode = ctx.createGain();
source.connect(gainNode);
gainNode.connect(ctx.destination);
document.getElementById('volume').onchange = function() {
gainNode.gain.value = this.value;
};
gainNode.gain.value = document.getElementById('volume').value;
new Audio().play();
}, function(e) {
alert(e);
});
// For the demo only:
document.getElementById('volume').onchange = function() {
alert('Please provide access to the microhone before using this.');
}
This is HTML control:这是 HTML 控制:
Volume: <input type=range id=volume min=0 max=100 value=50 step=0.01/>
From what I can tell, all I am doing with this code is lowering the output volume level from the microphone.据我所知,我对这段代码所做的只是降低麦克风的 output 音量。
As I said, I am trying to capture low volume input from 0Hz to 100Hz.正如我所说,我试图捕捉从 0Hz 到 100Hz 的低音量输入。
If you want record just the frequencies between 0 and 100 Hz, use one or more BiquadFilterNodes or an IIRFilterNode to implement a lowpass filter with a cutoff of 100 Hz or so.如果您只想记录 0 到 100 Hz 之间的频率,请使用一个或多个BiquadFilterNode或IIRFilterNode来实现一个截止频率为 100 Hz 左右的低通滤波器。
Generally, it's up to you to figure out the right filter, but perhaps this filter design page will be helpful.通常,由您决定正确的过滤器,但也许这个过滤器设计页面会有所帮助。 Use at your own risk!
使用风险自负!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.