From:  Morgane Daniel <>
Date:  13 Jun 2017 17:40:40 Hong Kong Time

MediaRecorder: how to get sample rate and sample size



I have a question regarding the MediaRecorder API, I hope this list is the
good place to ask this!
I try to record an audio track from the microphone and so far I succeed in
getting an array of bytes in a Blob. My problem is I could not get the
sample rate and the sample size. The method getSettings() seems to be the
perfect candidate but it is not supported on Chrome neither on Firefox. I
also tried the applyConstraints() method to fix a sample rate and a sample
size but it seems not being applied (I had no more bytes if I tried to
increase the sample rate for example), however I can read those constraints
in getConstraints.
Could you tell me what I am doing wrong please? I don't get it!
thank you !

let AudioFormat = {
            sampleSize: 16,
            channelCount: 1,
            sampleRate: 16000

       navigator.mediaDevices.getUserMedia({ audio: AudioFormat, video:
false })
            .then( function(stream) {
                const media_recorder = new MediaRecorder(stream);

                media_recorder.start( recording_length );
                media_recorder.onstart = function(){
                    console.log("Starting recording")

                media_recorder.ondataavailable =  function( event ){
                     var reader = new FileReader();
                     reader.addEventListener("loadend", function() {
                         console.log( new Uint8Array( reader.result ) )