|
|
|
@ -1,8 +1,6 @@
|
|
|
|
navigator.mediaDevices.getUserMedia({
|
|
|
|
navigator.mediaDevices.getUserMedia({
|
|
|
|
audio: true,
|
|
|
|
audio: true
|
|
|
|
video: true
|
|
|
|
}).then((stream) => {
|
|
|
|
})
|
|
|
|
|
|
|
|
.then(function(stream) {
|
|
|
|
|
|
|
|
const audioContext = new AudioContext();
|
|
|
|
const audioContext = new AudioContext();
|
|
|
|
const analyser = audioContext.createAnalyser();
|
|
|
|
const analyser = audioContext.createAnalyser();
|
|
|
|
const microphone = audioContext.createMediaStreamSource(stream);
|
|
|
|
const microphone = audioContext.createMediaStreamSource(stream);
|
|
|
|
@ -14,7 +12,7 @@ navigator.mediaDevices.getUserMedia({
|
|
|
|
microphone.connect(analyser);
|
|
|
|
microphone.connect(analyser);
|
|
|
|
analyser.connect(scriptProcessor);
|
|
|
|
analyser.connect(scriptProcessor);
|
|
|
|
scriptProcessor.connect(audioContext.destination);
|
|
|
|
scriptProcessor.connect(audioContext.destination);
|
|
|
|
scriptProcessor.onaudioprocess = function() {
|
|
|
|
scriptProcessor.onaudioprocess = () => {
|
|
|
|
const array = new Uint8Array(analyser.frequencyBinCount);
|
|
|
|
const array = new Uint8Array(analyser.frequencyBinCount);
|
|
|
|
analyser.getByteFrequencyData(array);
|
|
|
|
analyser.getByteFrequencyData(array);
|
|
|
|
const arraySum = array.reduce((a, value) => a + value, 0);
|
|
|
|
const arraySum = array.reduce((a, value) => a + value, 0);
|
|
|
|
@ -23,7 +21,7 @@ navigator.mediaDevices.getUserMedia({
|
|
|
|
// colorPids(average);
|
|
|
|
// colorPids(average);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
.catch((err) => {
|
|
|
|
/* handle the error */
|
|
|
|
/* handle the error */
|
|
|
|
console.error(err);
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|