JSFiddle - React, Tailwind, and code Playground
by kthornbloom
JavaScript
MicrophoneSample.prototype.getMicrophoneInput = function() {
// TODO(smus): Remove this ugliness.
var isLocalhost = window.location.hostname == 'localhost' ||
window.location.hostname == '127.0.0.1';
if (window.location.protocol != 'https:' && !isLocalhost) {
alert('HTTPS is required for microphone access, and this site has no SSL cert yet. Sorry!');
}
navigator.getUserMedia({audio: true},
this.onStream.bind(this),
this.onStreamError.bind(this));
};
MicrophoneSample.prototype.onStream = function(stream) {
var input = context.createMediaStreamSource(stream);
var filter = context.createBiquadFilter();
filter.frequency.value = 60.0;
filter.type = filter.NOTCH;
filter.Q = 10.0;
var analyser = context.createAnalyser();
// Connect graph.
input.connect(filter);
filter.connect(analyser);
this.analyser = analyser;
// Setup a timer to visualize some stuff.
requestAnimFrame(this.visualize.bind(this));
};