Search code examples
javascriptwebrtcmediarecorderweb-mediarecorder

Is it possible to get raw values of audio data using MediaRecorder()


I'm using MediaRecorder() with getUserMedia() to record audio data from the browser. It works, but recorded data is recorded in the Blob format. I want to get raw audio data (amplitudes), not the Blobs. Is it possible to do it?

My code looks like this:

  navigator.mediaDevices.getUserMedia({audio: true, video: false}).then(stream => {
    const recorder = new MediaRecorder(stream);
    recorder.ondataavailable = e => {
      console.log(e.data); // output: Blob { size: 8452, type: "audio/ogg; codecs=opus" }
    };
    recorder.start(1000); // send data every 1s
  }).catch(console.error);

Solution

  • MediaRecorder is useful to create files; if you want to do audio processing, Web Audio would be a better approach. See this HTML5Rocks tutorial which shows how to integrate getUserMedia with Web Audio using createMediaStreamSource from Web Audio.