/**
* filter media stream to reduce noise and more
* if not filtered or have any problem then
* return original stream itself
*
* @param stream MediaStream Source to Video tag
* @return MediaStream
*/
async function filterMediaStream(stream) {
try {
//filter media stream
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var source = audioCtx.createMediaStreamSource(stream);
var delay = audioCtx.createDelay(1.5);
// Create a biquadfilter
var biquadFilter = audioCtx.createBiquadFilter();
biquadFilter.Q.value = 8.5;
biquadFilter.frequency.value = 550;//350 - default value
biquadFilter.gain.value = 1;
biquadFilter.type = 'bandpass';
source.connect(biquadFilter);
biquadFilter.connect(delay);
delay.connect(audioCtx.destination);
//assign user media
return await stream;
} catch (error) {
return null
console.log('Error with media filtering: ', error.message, error.name);
//if u have problem with filtering media stream
//then return the original stream copy
}
}
No comments:
Post a Comment