I'm trying to do my first TypeScript/React project and I'm running into issues.
Using this answer, I have managed to read and play sound from my mic and also display some sample analysis data in the console. Now i'm trying to translate it into TS. Going step by step, I've arrived at this:
export class Processor {
readonly BUFFER_SIZE = 16384;
audioContext: AudioContext;
gainNode: GainNode;
microphoneStream: MediaElementAudioSourceNode;
constructor() {
this.audioContext = new AudioContext();
console.log('audio is starting up ...');
if (navigator.getUserMedia) {
navigator.getUserMedia(
{ audio: true },
function (stream) {
startMicrophone(stream);
},
function (e) {
alert('Error capturing audio.');
});
} else {
alert('Seems like this browser might not be supported.');
}
}
private startMicrophone(stream: MediaStream) {
this.gainNode = this.audioContext.createGain();
this.gainNode.connect(this.audioContext.destination);
this.microphoneStream =
this.audioContext.createMediaStreamSource(stream);
}
}
Except the call to startMicrophone gives me
'Cannot find name 'startMicrophone'.'
I also tried to refer to it with this
, which results in a different error:
''this' implicitly has type 'any' because it does not have a type annotation.'
I don't know what I'm doing wrong and could really use a bit of guidance.