0

With an ionic angular app, I am trying to get the audio signal from navigator.getMediaDevices({ audio : true} ) to then use an audio analyser to get the float time domain data.

The code executes as follows:

somewhere in the service constructor:

this.audioContext = new window.AudioContext();
this.analyser = this.audioContext.createAnalyser();
this.analyser.fftSize = this.settings.values.fftSize; // Valued 8192
this.audioBuffer = new Float32Array(this.analyser.fftSize);

Then, somewhere else I toggle the stream with getUserMedia

 navigator.mediaDevices.getUserMedia({ audio: true, video: false })
    .then((stream => {
      //console.log('Mic stream OK! ', stream);
      this.stream = stream;
      this.isCapturing = true;
      // Create an AudioNode from the stream
      this.mediaStreamSource = this.audioContext.createMediaStreamSource(this.stream);
      this.mediaStreamSource.connect(this.analyser);

      //start the analysis cycle. This is non related but it starts the cycle that uses the getfloatTimeDomainData(buffer)
      this.animationFrame = requestAnimationFrame(this.streamAnalysis.bind(this));
    }).bind(this))
    .catch(err => console.log('[PMATIC] Error accessing mic: ', err));

this prompts my users to enable the app to listen from the microphone enter image description here enter image description here

And then, in the analysis cycle (The cycle is constantly recording until the user prompts it to stop)

private tuneAnalysis():void { this.analyser.getFloatTimeDomainData(this.audioBuffer);

However, whenever I access this.audioBuffer, the array elements are always equal to 0. enter image description here Sometimes it works, but 99% of the times it doesn't. This used to work and works fine when I deploy in a mobile android app using cordova, however, here, in google chrome it simply doesn't ,or at least not reliably. And I can't seem to find a pattern of why it works or it doesn't work. I've checked my microphone and in use with other apps it works correctly. No exception is raised, i can record from my mic perfectly with other apps, and I also ensure other apps that may be using the microphone are closed when I try to record. I'm using typescript and i've tried declaring the variables both public and private but it doesn't really work.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Juan Vilar
  • 435
  • 3
  • 11
  • Possible duplicate: [see](https://stackoverflow.com/questions/16898307/zero-value-data-in-createmediastreamsource-input-buffer-when-recording-using-web) – Jerboas86 Nov 18 '21 at 15:41
  • Nope, not at all, but I just realized the problem lies here: https://stackoverflow.com/questions/55026293/google-chrome-javascript-issue-in-getting-user-audio-the-audiocontext-was-not Apparently this has been newly enforced in a new chrome update. so that's why it stopped working. THANK YOU GOOGLE for doing this. I love spending hours trying to figure out why things stopped working out of no where. – Juan Vilar Nov 19 '21 at 15:06

0 Answers0