0

one-line version of my question: How can I record lossless ( or at the least, incredibly high quality ) audio in a web browser? Preferably chrome/chromium since I would like to make a high quality audio-recording electron application.

Note, this question was asked 8 years ago, but I'm trying to find a modern 2022 solution: High Quality Audio Recording in Web Browser

I have tried using getUserMedia() to record audio in javascript, even specifying audio quality variables like so:

    var constraints = {
        audio: true,
        "mandatory": {
            //sampleSize: 32,
            //sampleRate
            channelCount: 2,
            //autoGainControl: false,
            //noiseSuppression: false,
            //echoCancellation: false,
            "googEchoCancellation": "false",
            "googAutoGainControl": "false",
            "googNoiseSuppression": "false",
            "googHighpassFilter": "false"
        },
        video: false
    };

This code is in my repo: https://github.com/MartinBarker/simple-web-audio-recorder-demo The audio recording works but comes out still very low quality: windows file browser says the saved wav file is 705kbps, Spek shows it as being 16bit, 1411kbps, 44100Hz, 1 channel, and the file sounds awful.

enter image description here

Compare that to audacity, recording using the same microphone on the same computer, I can output a wav file that is signed 32 bit, with windows saying it has a bitrate of 2822kbps, and Spek showing a 32bit, 2822kbps, 44100hz, 2channel file which sounds great.

enter image description here

I am trying to record a wav file in my chrome browser with similar quality to audacity, is this even possible? Are there any other web libraries which could help me reach this goal?

O. Jones
  • 103,626
  • 17
  • 118
  • 172
Martin
  • 1,336
  • 4
  • 32
  • 69
  • 44100Hz 16-bit audio is (literally) CD quality (though CDs have 2 channels, for stereo). You're likely not writing the original audio to the PCM file, but a somehow compressed stream (that's decoded back to PCM). – AKX Jan 11 '22 at 20:46
  • As far as I know OPUS is the highest quality we get in most cases without encoding/decoding if it were done over browser the streaming. As sample-rate/bits, the standard for online transmission is 48KHz@16bit (24-bit if you want). This ensures all sounds can be heard like the highest notes of a saxophone later discovered (but that's may irrelevant here). OPUS is the standard through browsers. :) – BGPHiJACK Jan 11 '22 at 20:46
  • I'll add, your settings for WebRTC are not set for high quality, use echoCancellation, autoGainControl, noiseSuppression as your settings and I don't believe you should be using mandatory it's basic options seek webrtc for proper deploy. goog is not really standard or considered when setting these, it may work but don't rely on them. – BGPHiJACK Jan 11 '22 at 20:50

2 Answers2

1

The output from the MediaRecorder module in Chrome and other browsers is, always, compressed. You can certainly decompress it and get .WAV sampled audio from it, but its fidelity will always be affected by the codec. You can crank up Opus to a high sample rate and a not-so-aggressive compression ratio, but it's still compressed. If you want Audacity-style fidelity you need to use a desktop product whose media interface isn't constrained by browser WebRTC.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • can you tell the compression from the spectrograph? if the opus recorder is running in say electron on a chromium window as a desktop application, would the current web tech and compression like you mention reduce the quality no matter what? The kbps stats in the spectrogram of my recording would make it seem to appear like a high quality recording – Martin Feb 06 '22 at 05:25
  • I suggest you investigate the [Web Audio API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API). I haven't used it so I can't give detailed advice. – O. Jones Feb 06 '22 at 12:24
0

@BGPHiJACK in the comments was right, opus media recorder is good for recording 32 bit, 2822kbps, 44100 Hz, 2 channel wav audio from a chrome browser: https://github.com/MartinBarker/opus-recorder?organization=MartinBarker&organization=MartinBarker

Martin
  • 1,336
  • 4
  • 32
  • 69