如何使用Web Audio API降低麦克风输入的噪音?

时间:2013-06-05 20:59:05

标签: javascript html5-audio web-audio

我一直在玩Web Audio API并使用笔记本电脑的麦克风作为输入源。我听到输入的时候听到很多白噪声;如何创建滤镜以降低噪音,使声音更清晰?是否有任何库为这种情况提供预先编写的噪声滤波器?

2 个答案:

答案 0 :(得分:2)

'`正在研究一些POC并减少了笔记本电脑和生活中的鼻子"使用BiquadFilter。我也使用压缩机,但你不必))

(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 );
    }
})();

答案 1 :(得分:0)

如果你听到的是嘶嘶声而不是全谱噪声,你可以试试一种高通滤波器。我相信Web Audio API具有您可以实现的那种过滤器。