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?
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?
Share Improve this question asked Jun 5, 2013 at 20:59 Timothy ArmstrongTimothy Armstrong 2,0624 gold badges17 silver badges19 bronze badges 4- There is no such thing as a magic noise filter. There are lots of ways noise is introduced, and lots of ways to remove it depending on the kind of noise you are dealing with. Also, are you looking to filter this noise client-side, or on a server? When you filter out noise, you filter the signal as well, reducing audio quality. perhaps a simple noise gate is all you need? What is your application? – Brad Commented Jun 5, 2013 at 21:03
- I realize that there is no "magic filter", but I presume that there are standard methods that people use to build a noise filter. I'm using the Web Audio API, so this would be client-side. Maybe a noise gate is what I'm looking for, how does one go about creating one? – Timothy Armstrong Commented Jun 5, 2013 at 21:08
- I'm not too familiar with the Web Audio API, but in general, a gate is just that no audio is let through until the level reaches a certain threshold. The idea is that when you aren't talking, no audio es through. You don't hear the noise (or anything) when the level is below the threshold. When it is above, you will hear the noise but it will be masked by your voice. Another method is to take a spectral sample of the noise and then substract that spectrum from the stream. This is better for a specific kind of noise, like 60hz leaking in. It also reduces the quality of audio. – Brad Commented Jun 5, 2013 at 22:55
- it tends to be pretty difficult to filter out ambient noise in a way that doesn't sound harsh. Recording engineers will use gates on drums - but the unnatural sound can be masked by the rest of the mix. As far as I know, there aren't any libraries for the Web Audio API that implement a gate - and there's no gate or expander in the spec. You could write one, but it's non-trivial since you'd need controls for threshold, attack/release, and hold. Depending on what you're trying to do, your best bet is probably to try and find a less noisy environment. Good rooms + good sources = good signals. – Kevin Ennis Commented Jun 7, 2013 at 2:21
2 Answers
Reset to default 3'`m working on some POC and reduced laptop "life noses" with a BiquadFilter. I have also use a pressor but you don't have to ))
(function(){
var filter, pressor, 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) {
pressor = context.createDynamicsCompressor();
pressor.threshold.value = -50;
pressor.knee.value = 40;
pressor.ratio.value = 12;
pressor.reduction.value = -20;
pressor.attack.value = 0;
pressor.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(pressor);
pressor.connect(context.destination)
filter.connect(context.destination)
mediaStreamSource = context.createMediaStreamSource( stream );
mediaStreamSource.connect( filter );
}
})();
You might try a type of high pass filter if what you're hearing is more of a hiss than full-spectrum noise. I believe the Web Audio API has that type of filter that you could implement.