Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reduce the noise of a microphone input with the Web Audio API?

I've been playing around with the Web Audio API and using my laptop's microphone as an input source. I can hear a lot of white noise when I listen to the input though; how can I create a filter to reduce the noise so that the sound is clearer? Are there any libraries that provide a pre-written noise filter for this situation?

like image 776
Timothy Armstrong Avatar asked Jun 05 '13 20:06

Timothy Armstrong


1 Answers

'`m working on some POC and reduced laptop "life noses" with a BiquadFilter. I have also use a compressor but you don't have to ))

(function(){
    var filter, compressor, mediaStreamSource;

    // Start off by initializing a new context.
    var context = new (window.AudioContext || window.webkitAudioContext)();


    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
    navigator.getUserMedia( {audio:true}, initAudio , function(err){
        console.log('usermedia error', err)
    });



    function initAudio(stream) {
        compressor = context.createDynamicsCompressor();
        compressor.threshold.value = -50;
        compressor.knee.value = 40;
        compressor.ratio.value = 12;
        compressor.reduction.value = -20;
        compressor.attack.value = 0;
        compressor.release.value = 0.25;

        filter = context.createBiquadFilter();
        filter.Q.value = 8.30;
        filter.frequency.value = 355;
        filter.gain.value = 3.0;
        filter.type = 'bandpass';
        filter.connect(compressor);


        compressor.connect(context.destination)
        filter.connect(context.destination)

        mediaStreamSource = context.createMediaStreamSource( stream );
        mediaStreamSource.connect( filter );
    }
})();
like image 170
user3711277 Avatar answered Nov 14 '22 23:11

user3711277