0

I aim to capture sound via microphone and then process it. To do that I need to obtain the number of channels, sampling rate and sampling size of the audio.

For recording I use MediaRecorder, which works just fine:

    navigator.mediaDevices.getUserMedia (
           {
              audio: true
           })
           .then(function(stream) {
                const mediaRecorder = new MediaRecorder(stream);
                set_record(mediaRecorder)
                set_stop(mediaRecorder)
           });

After being done recording I create blob of type 'audio/flac' as follows:

            let chunks = [];
            mediaRecorder.ondataavailable = function(e){
                chunks.push(e.data);
            }
            mediaRecorder.onstop = function(e){
                const blob = new Blob(chunks, { 'type' : 'audio/flac;' });
                chunks = [];
            }

Now the problem is that if I download the blob and try to read it, its metadata are weird. I haven't found any documentation as to how should I read it. The closest is this StackOverflow question that is left unanswered link.

I have tried different codecs each giving me the same metadata part with slight nuances on different browsers.

Is there a way to set the parameters to get an audio file with a given sampling rate/channel count/sampling size? If so, can I rely on it to be the same across different browsers? Or is there a way to read the metadata or tell it to write desired parameters into them?

Jan Kleprlík
  • 320
  • 3
  • 12
  • 1
    When faced with the same problem during the saving of webm files (video in his case), a fellow user located a library with a solution that was acceptable. It seems to be a problem somewhere in the MediaRecorder/Blob interfaces. You don't get the info for any output type I've read about. The solution found involves a low-level look at the produced binary (webm) files! https://stackoverflow.com/questions/63640361/how-to-add-duration-to-metadata-of-files-recorder-by-mediarecorder – enhzflep Feb 10 '21 at 11:08
  • Thank you. I was expecting to do some low-level look at the binary however, I just can't make sense of the data it produces. I guess I must find something similar to the list of sections as in the package mentioned in the question you linked. – Jan Kleprlík Feb 10 '21 at 12:10

0 Answers0