chrisguttandin / extendable-media-recorder

An extendable drop-in replacement for the native MediaRecorder.
MIT License
258 stars 13 forks source link

Any way to get audioBitsPerSecond #643

Open bryanmcgrane opened 3 years ago

bryanmcgrane commented 3 years ago

Hello! I would like to obtain the audioBitsPerSecond via: https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/audioBitsPerSecond

Is there any way I can get this from the MediaRecorder object?

chrisguttandin commented 3 years ago

Unfortunately that's not yet implemented. I'm also not really sure how it's supposed to work. It doesn't work the same in Chrome and Firefox. On top of that the number returned in Chrome isn't always correct.

In case you just want to know the audioBitsPerSecond value of the wav encoder it can be computed with the following formula.

16 /* bitsPerSample */ * sampleRate * numberOfChannels
bryanmcgrane commented 3 years ago

I ended up parsing the wav file header and grabbing the info from that :)

chrisguttandin commented 3 years ago

Okay, great. I think we should leave the issue open until it get's finally implemented.

Just in case someone else needs this before I guess you used something like this to read the value from the first Blob, right?

const arrayBuffer = await blob.arrayBuffer();
const dataView = new DataView(arrayBuffer);
const audioBitsPerSecond = dataView.getUint32(28, true);
bryanmcgrane commented 3 years ago

Yes that's exactly what I did!