From b05bf1bb17d25237fd1ce1d54e2aaf9536d0c506 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 23 Apr 2026 02:30:45 -0500 Subject: [PATCH] feat(audio): fix Codec2MicrophoneRecorder with silent tap for audio processing and ensure audio context resumes correctly --- .../codec2-microphone-recorder.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/meshchatx/src/frontend/public/assets/js/codec2-emscripten/codec2-microphone-recorder.js b/meshchatx/src/frontend/public/assets/js/codec2-emscripten/codec2-microphone-recorder.js index 5760a5c..163773b 100644 --- a/meshchatx/src/frontend/public/assets/js/codec2-emscripten/codec2-microphone-recorder.js +++ b/meshchatx/src/frontend/public/assets/js/codec2-emscripten/codec2-microphone-recorder.js @@ -33,6 +33,18 @@ class Codec2MicrophoneRecorder { // send mic audio to audio worklet this.mediaStreamSource = this.audioContext.createMediaStreamSource(this.microphoneMediaStream); this.mediaStreamSource.connect(this.audioWorkletNode); + this._silentTap = this.audioContext.createGain(); + this._silentTap.gain.value = 0; + this.audioWorkletNode.connect(this._silentTap); + this._silentTap.connect(this.audioContext.destination); + + if (typeof this.audioContext.resume === "function") { + try { + await this.audioContext.resume(); + } catch { + // ignore + } + } // successfully started recording return true; @@ -58,6 +70,15 @@ class Codec2MicrophoneRecorder { this.audioWorkletNode.disconnect(); } + if (this._silentTap) { + try { + this._silentTap.disconnect(); + } catch { + // ignore + } + this._silentTap = null; + } + // close audio context if (this.audioContext && this.audioContext.state !== "closed") { this.audioContext.close();