Trying to modify this code to use mp3 as source instead of getUserMedia microphone, but I’m not too familiar with the Web Audio API so I’m missing something and getting Uncaught TypeError: Failed to execute 'connect' on 'AudioNode': Overload resolution failed.
AudioAnalyzer.prototype.initWithoutStream = function () {
/// modify code to use mp3 as source instead of browser microphone
var audio = new Audio();
audio.src = '/try.mp3';
audio.controls = true;
audio.autoplay = true;
document.body.appendChild(audio);
////
const audioCtx = new (
window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.msAudioContext)();
this.gain = audioCtx.createGain();
this.gain.gain.value = 70.;
const lowPass = audioCtx.createBiquadFilter();
lowPass.type = "lowpass";
lowPass.frequency.value = 1000;
const highPass = audioCtx.createBiquadFilter();
highPass.type = "highpass";
highPass.frequency.value = 20000;
this.analyzer = audioCtx.createAnalyser();
this.analyzer.fftSize = this.FFT_SIZE;
// const mediaStreamSource = audioCtx.createMediaStreamSource(stream);
var source = audioCtx.createMediaElementSource(audio);
source.connect(this.analyser); // ERROR
this.analyser.connect(audioCtx.destination);
// ^^^ modified / added ^^^
// Node tree
// mediaStreamSource.connect(this.gain);
source.connect(this.gain);
this.gain.connect(lowPass);
this.gain.connect(highPass);
lowPass.connect(this.analyzer);
highPass.connect(this.analyzer);
this.reset();
this.audioBuffer = new Uint8Array(this.analyzer.frequencyBinCount);
this.isInit = true;
this.isPulse = true;
};