Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poor audio quality with getUserMedia. Any ideas why?

I'm trying to set up an audio recorder in a React web application for recording large groups of people (15+) talking, but can't seem to get the recording quality right. I initially tried capturing the audio recordings by passing the following constraints to getUserMedia:

const constraints = {
  audio: {
    sampleRate: 48000,
    channelCount: 1,
    volume: 1.0,
    echoCancellation: true,
    noiseSuppression: true,
  },
  video: false
}

navigator.mediaDevices.getUserMedia(constraints)
.then( stream => {
  this.processStream(stream);
})

processStream = stream => {
  let options = MediaRecorder.isTypeSupported('audio/webm') ? {
    mimeType: 'audio/webm'
  } : {};

  let recorder = new MediaRecorder(stream, options);

  ...

}

For most recordings, the recording quality was good. Sometimes, however, the recording would end up with the this really bad, distorted, almost metallic-sounding quality. I haven't been able to figure out how to reproduce the effect (I have since started capturing the users' browser, to try to help debug this problem).

About a week ago, I deployed the app with constraints = { audio: true, video: false }, but this too sometimes produces recordings with slightly distorted qualities. So far, none of the recordings have been as bad as some of the recordings before, but the quality is still not where we want it to be.

Today, I set the constraints to:

const constraints = {
    audio: {
      echoCancellation: false,
      autoGainControl: false,
      noiseCancellation: false
    },
    video: false
}

But I'm doubtful that this will be the magic ticket to high quality recordings, and I'm starting to think that maybe I should ditch MediaRecorder for something else. Does anyone have ideas about 1) what the problem is and 2) how we might fix it?

Thanks!

like image 440
Nicole Hemenway Avatar asked Mar 25 '18 15:03

Nicole Hemenway


People also ask

Why is my audio quality so bad on YouTube?

If the audio quality is poor, check to make sure that the file you delivered meets the specifications. If you delivered an MP3 file, for example, it likely has a low bit rate causing it to sound poor on YouTube. Redeliver the track with a higher quality audio file, preferably in an uncompressed format.

Why is my audio quality so low on Microsoft Teams?

So clearly Teams is downgrading sound quality for all audio (not only the Teams call) played on the same output device as Teams using. By the way there is no issue while using other conferencing tools, this audio quality issue is only happening on Teams. May 27 2020 01:56 PM May 27 2020 01:56 PM Same issue here.

How do I send all audio constraints to getUserMedia?

All constraints can be sent to getUserMedia () as a property of the audio object inside the constraints object. Here’s an example using the newer promise based getUserMedia ():

Why is my audio so bad when I share from desktop?

Somehow, teams is affecting the audio quality on the entire device - which in turns results in really poor audio when you share from desktop. As soon as I close the teams chat BOOM audio comes clean again...


1 Answers

You should never set the sampleRate value in the getUserMedia constraints! The sampleRate is set by the client automatically and modifying it would result in gaping sounds. The value you set, 48000, for example, is compatible only with Google Chrome. Firefox and Edge use totally different values.

Also, when you set echoCancellation and noiseSuppression to true, this means the microphone will mute itself when the gain is close to 0. This will result in broken speech when the person starts to talk and ends his sentences.

From my own experience, you should just set the constrains to audio alone, and let the browser do the rest:

const constraints = {
  audio: true,
  video: false
}
like image 56
Koby Douek Avatar answered Sep 19 '22 05:09

Koby Douek