webrtcwavaudio-streamingpcmrecordrtc

Calculate audio time from RecordRTC blob


I'm trying to calculate the audio time from the RecordRTC blobs I received. I have specified the timeSlice=500ms, desiredSampRate=16kHz, numberOfAudioChannels=1, mimeType='audio/webm;codecs=pcm'. I have printed out the blob type in event listener ondataavailable, and the type is "audio/wav".

two possible ways to calculate:

  1. if timeSlice is accurate and I can trust it, I just need to count number of blobs I got * 500ms.
  2. Look at the byte count, and calculate with byte length / (sample rate * channel count * (bit depth / 8)). However, it seems that RecordRTC might be storing headers along with audio bytes in a blob (don't know if this is the case).

Any idea which approach is the right one?


Solution

    1. if timeSlice is accurate and I can trust it, I just need to count number of blobs I got * 500ms.

    The time slice parameter is advisory only. The duration of the blob you get will be close to that, but may not be exactly 500 milliseconds. Usually, a sound card will produce chunks in a number of samples, such as 256 or 512 samples at a time. This will pass through all the way up to the user agent, which then buffers them and muxes them into the container. Once the timeslice duration has been reached, it will emit a blob... but this may be slightly different in duration what you requested.

    1. Look at the byte count, and calculate with byte length / (sample rate * channel count * (bit depth / 8)). However, it seems that RecordRTC might be storing headers along with audio bytes in a blob (don't know if this is the case).

    Yes, this is generally the way. Count the number of samples per channel in each blob. And yes, it's possible there will be headers in your blob, especially if its the first blob. You'll have to parse out the specific container to determine how many samples are in each.

    If you convert each blob to raw PCM, you'll be able to calculate easily.