Bug 262759

Summary: When recording audio, volume of recording diminishes after several seconds
Product: WebKit Reporter: bryce.a.aebi
Component: MediaAssignee: Nobody <webkit-unassigned>
Status: RESOLVED WONTFIX    
Severity: Normal CC: cdumez, eric.carlson, jer.noble, youennf
Priority: P2    
Version: Safari 16   
Hardware: Mac (Apple Silicon)   
OS: Unspecified   

Description bryce.a.aebi 2023-10-05 21:32:40 PDT
I am recording audio in Safari from a Macbook pro microphone using the following basic code:
 

 const createStream = async () => {
    // For iOS Safari, reset to play-and-record to allow mic to work
    if ((isIOS || isSafari) && navigator.audioSession) {
      navigator.audioSession.type = "play-and-record";
    }

    const stream = await navigator.mediaDevices.getUserMedia({
      video: false,
      audio: true,
    });

    return stream;
  };

Without fail, the volume of the audio recording starts out at the expected level and then it diminishes in volume (maybe by more than 50%) after about 5 seconds. This happens both when I record and then play back the audio and also when I run an AnalyserNode on the audio in real time and view the audio data live.
Comment 1 bryce.a.aebi 2023-10-05 21:51:15 PDT
Another important detail I've realized -- this only appears to happen when humming a fixed pitch.

If I speak normally into the microphone, all of the audio is picked up as expected.
Comment 2 Alexey Proskuryakov 2023-10-09 16:55:41 PDT
This sounds like it could be expected effect of noise reduction, does this reproduce with it disabled in macOS GUI?
Comment 3 bryce.a.aebi 2023-10-09 18:57:37 PDT
Yes, it looks like this was an artifact of noise reduction.

When I change the code to this the issue is resolved:

const stream = await navigator.mediaDevices.getUserMedia({
    audio: {
        autoGainControl: false,
        echoCancellation: false,
        noiseSuppression: false,
    }
});

Thanks for taking a look
Comment 4 youenn fablet 2023-10-10 02:05:32 PDT
Marking as WontFix since this is expected behaviour. Please reopen if needed.