extendable-media-recorder icon indicating copy to clipboard operation
extendable-media-recorder copied to clipboard

Any way to get audioBitsPerSecond

Open bryanmcgrane opened this issue 3 years ago • 4 comments

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?

bryanmcgrane avatar May 09 '21 13:05 bryanmcgrane

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

chrisguttandin avatar May 10 '21 09:05 chrisguttandin

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

bryanmcgrane avatar May 11 '21 02:05 bryanmcgrane

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);

chrisguttandin avatar May 11 '21 19:05 chrisguttandin

Yes that's exactly what I did!

bryanmcgrane avatar May 11 '21 20:05 bryanmcgrane