I need to get the Sample Rate of Audio file, loaded by standard input element. I tried to use this function
function func(e) {
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 it always displays one incorrect answer 48000 regardless of file.
So I try to calculate the Sample Rate with formula
SampleRate = File.size/(NumberOfChannels*BitDepth*File.duration);
But I dont know how to get the value of audio BitDepth. Please, help.