0

I'm trying to get the sample rate information of a file before uploading it to server, need to access this for some validation purpose on browser.

What I did so far

let reader = new FileReader();
reader.readAsArrayBuffer(e.files[0]);
reader.onload = function (event) {
  let buffer = reader.result;
  let AudioContext = window.AudioContext || window.webkitAudioContext;
  let context = new AudioContext();
  context.decodeAudioData(buffer, function (buffer1) {
    console.log(buffer1.sampleRate);
  });
}

But this always gives some constant result regardless of file selected. Can anyone suggest what is wrong here or any other idea to achieve the same?

Pradip Dhakal
  • 1,872
  • 1
  • 12
  • 29
phpLover
  • 155
  • 1
  • 2
  • 14

0 Answers0