简体   繁体   中英

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. So essentially I'm looking to record in low frequencies or decibels that start from 0Hz to around 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:

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.

As I said, I am trying to capture low volume input from 0Hz to 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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM