From 75de8f1d2bc2cfde087116e52796a2a0e32f82b7 Mon Sep 17 00:00:00 2001 From: illusia <64828020+EchoSixHIYA@users.noreply.github.com> Date: Tue, 15 Sep 2026 22:05:15 +0800 Subject: [PATCH] test: use native microphone noise suppression --- web/src/composables/useVoiceWebSocket.ts | 21 +++++++++++++++++- web/src/views/WebClient.vue | 28 +++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/web/src/composables/useVoiceWebSocket.ts b/web/src/composables/useVoiceWebSocket.ts index 98c2f37..e1f0b86 100644 --- a/web/src/composables/useVoiceWebSocket.ts +++ b/web/src/composables/useVoiceWebSocket.ts @@ -41,6 +41,12 @@ export interface AudioOutputDevice { export type AudioPermission = "unknown" | "granted" | "denied"; +export interface MicrophoneProcessingSettings { + echoCancellation: boolean | null; + noiseSuppression: boolean | null; + autoGainControl: boolean | null; +} + type SinkAudioContext = AudioContext & { setSinkId?: (sinkId: string) => Promise; }; @@ -171,6 +177,11 @@ export function useVoiceWebSocket() { const selectedOutputDeviceId = ref(typeof localStorage !== "undefined" ? localStorage.getItem("webspeak:output-device") ?? "" : ""); const outputDeviceSupported = ref(false); const audioPermission = ref("unknown"); + const microphoneProcessing = reactive({ + echoCancellation: null, + noiseSuppression: null, + autoGainControl: null, + }); const audioContextState = ref("unknown"); const micLevel = ref(0); const microphoneTestActive = ref(false); @@ -364,7 +375,9 @@ export function useVoiceWebSocket() { channelCount: { ideal: 1 }, echoCancellation: true, noiseSuppression: true, - autoGainControl: true, + // Keep the microphone's natural dynamics. Browser AGC can make speech + // pump in volume, especially while background noise changes. + autoGainControl: false, }; if (selectedInputDeviceId.value) constraints.deviceId = { exact: selectedInputDeviceId.value }; return constraints; @@ -416,6 +429,11 @@ export function useVoiceWebSocket() { if (error instanceof DOMException && ["NotAllowedError", "SecurityError"].includes(error.name)) audioPermission.value = "denied"; throw error; } + const microphoneTrack = nextStream.getAudioTracks()[0]; + const settings = microphoneTrack?.getSettings(); + microphoneProcessing.echoCancellation = typeof settings?.echoCancellation === "boolean" ? settings.echoCancellation : null; + microphoneProcessing.noiseSuppression = typeof settings?.noiseSuppression === "boolean" ? settings.noiseSuppression : null; + microphoneProcessing.autoGainControl = typeof settings?.autoGainControl === "boolean" ? settings.autoGainControl : null; stopMicrophone(false); micStream = nextStream; @@ -1715,6 +1733,7 @@ export function useVoiceWebSocket() { selectedOutputDeviceId, outputDeviceSupported, audioPermission, + microphoneProcessing, audioContextState, identityMaterial, micLevel, diff --git a/web/src/views/WebClient.vue b/web/src/views/WebClient.vue index 72b2c30..9a10b61 100644 --- a/web/src/views/WebClient.vue +++ b/web/src/views/WebClient.vue @@ -292,7 +292,7 @@