mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
Add auto gain control toggle for echo cancellation tuning (#2)
Exposes autoGainControl as its own Options -> Aufnahme toggle (was implicitly left to the browser default) and requests the pipeline's own 48kHz sample rate explicitly, so the mic doesn't need an extra internal resample before the browser's own AEC runs. Both are standard getUserMedia constraints, honored the same way by Chromium and Firefox (unlike vendor-prefixed googEchoCancellation-style flags, which only affect Chromium). Helps speaker+mic (no headset) setups where AGC re-amplifying the mic signal after AEC can bring back audible echo residue - see #2.
This commit is contained in:
1 parent
24f070ce67
commit
f490ca5776
3 files changed
+45
No files matched your search
@@ -136,6 +136,7 @@ const INPUT_DEVICE_KEY = "webspeak3:input-device";
|
||||
const PLAYBACK_VOLUME_KEY = "webspeak3:playback-volume";
|
||||
const NOISE_SUPPRESSION_KEY = "webspeak3:noise-suppression";
|
||||
const ECHO_CANCELLATION_KEY = "webspeak3:echo-cancellation";
|
||||
const AUTO_GAIN_CONTROL_KEY = "webspeak3:auto-gain-control";
|
||||
const VAD_HANGOVER_KEY = "webspeak3:vad-hangover";
|
||||
const DESIGN_THEME_KEY = "webspeak3:design-theme";
|
||||
// The user's actual pick - "standard" | "nova" | "custom:<id>". DESIGN_THEME_KEY above
|
||||
@@ -3397,6 +3398,8 @@ interface AudioSettings {
|
||||
onToggleNoiseSuppression: () => void;
|
||||
echoCancellationEnabled: boolean;
|
||||
onToggleEchoCancellation: () => void;
|
||||
autoGainControlEnabled: boolean;
|
||||
onToggleAutoGainControl: () => void;
|
||||
}
|
||||
|
||||
function MicLevelBar({ levelRef, active }: { levelRef: React.MutableRefObject<number>; active: boolean }) {
|
||||
@@ -3587,6 +3590,14 @@ function AufnahmePanel({ audio }: { audio: AudioSettings }) {
|
||||
/>
|
||||
{t("recording.noiseSuppression")}
|
||||
</label>
|
||||
<label className="ts-options-checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={audio.autoGainControlEnabled}
|
||||
onChange={audio.onToggleAutoGainControl}
|
||||
/>
|
||||
{t("recording.autoGainControl")}
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
@@ -4555,6 +4566,9 @@ function AppInner() {
|
||||
const [echoCancellationEnabled, setEchoCancellationEnabled] = useState(() =>
|
||||
loadBoolPref(ECHO_CANCELLATION_KEY, true)
|
||||
);
|
||||
const [autoGainControlEnabled, setAutoGainControlEnabled] = useState(() =>
|
||||
loadBoolPref(AUTO_GAIN_CONTROL_KEY, true)
|
||||
);
|
||||
const [micTestOn, setMicTestOn] = useState(false);
|
||||
const [connectionsMenuOpen, setConnectionsMenuOpen] = useState(false);
|
||||
// Nova-theme-only: collapses the classic menu items behind a hamburger button.
|
||||
@@ -4714,6 +4728,10 @@ function AppInner() {
|
||||
localStorage.setItem(ECHO_CANCELLATION_KEY, echoCancellationEnabled ? "1" : "0");
|
||||
}, [echoCancellationEnabled]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(AUTO_GAIN_CONTROL_KEY, autoGainControlEnabled ? "1" : "0");
|
||||
}, [autoGainControlEnabled]);
|
||||
|
||||
useEffect(() => {
|
||||
if (inputDeviceId) localStorage.setItem(INPUT_DEVICE_KEY, inputDeviceId);
|
||||
}, [inputDeviceId]);
|
||||
@@ -5526,6 +5544,7 @@ function AppInner() {
|
||||
deviceId?: string;
|
||||
echoCancellation?: boolean;
|
||||
noiseSuppression?: boolean;
|
||||
autoGainControl?: boolean;
|
||||
}) => {
|
||||
const audioContext = ensureAudioContext();
|
||||
try {
|
||||
@@ -5542,6 +5561,7 @@ function AppInner() {
|
||||
deviceId: overrides?.deviceId ?? (inputDeviceId || undefined),
|
||||
echoCancellation: overrides?.echoCancellation ?? echoCancellationEnabled,
|
||||
noiseSuppression: overrides?.noiseSuppression ?? noiseSuppressionEnabled,
|
||||
autoGainControl: overrides?.autoGainControl ?? autoGainControlEnabled,
|
||||
});
|
||||
await mic.start();
|
||||
micCaptureRef.current = mic;
|
||||
@@ -5558,6 +5578,7 @@ function AppInner() {
|
||||
deviceId?: string;
|
||||
echoCancellation?: boolean;
|
||||
noiseSuppression?: boolean;
|
||||
autoGainControl?: boolean;
|
||||
}) => {
|
||||
micCaptureRef.current?.stop();
|
||||
micCaptureRef.current = null;
|
||||
@@ -5599,6 +5620,12 @@ function AppInner() {
|
||||
if (micCaptureRef.current) void restartMic({ echoCancellation: next });
|
||||
};
|
||||
|
||||
const handleToggleAutoGainControl = () => {
|
||||
const next = !autoGainControlEnabled;
|
||||
setAutoGainControlEnabled(next);
|
||||
if (micCaptureRef.current) void restartMic({ autoGainControl: next });
|
||||
};
|
||||
|
||||
const handleToggleMicTest = () => {
|
||||
const next = !micTestOn;
|
||||
setMicTestOn(next);
|
||||
@@ -7309,6 +7336,8 @@ function AppInner() {
|
||||
onToggleNoiseSuppression: handleToggleNoiseSuppression,
|
||||
echoCancellationEnabled,
|
||||
onToggleEchoCancellation: handleToggleEchoCancellation,
|
||||
autoGainControlEnabled,
|
||||
onToggleAutoGainControl: handleToggleAutoGainControl,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -291,6 +291,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"recording.typingAttenuation": "Typing attenuation",
|
||||
"recording.echoCancellation": "Echo Dämpfung",
|
||||
"recording.noiseSuppression": "Hintergrundgeräusche entfernen",
|
||||
"recording.autoGainControl": "Automatische Verstärkung",
|
||||
|
||||
"info.address": "Adresse:",
|
||||
"info.version": "Version:",
|
||||
@@ -813,6 +814,7 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"recording.typingAttenuation": "Typing attenuation",
|
||||
"recording.echoCancellation": "Echo cancellation",
|
||||
"recording.noiseSuppression": "Remove background noise",
|
||||
"recording.autoGainControl": "Automatic gain control",
|
||||
|
||||
"info.address": "Address:",
|
||||
"info.version": "Version:",
|
||||
|
||||
@@ -36,6 +36,11 @@ export interface MicCaptureOptions {
|
||||
deviceId?: string;
|
||||
echoCancellation?: boolean;
|
||||
noiseSuppression?: boolean;
|
||||
/** Automatic gain control. Exposed as its own toggle (rather than folded into
|
||||
* echoCancellation) because AGC re-amplifying the mic signal after the
|
||||
* browser's own AEC runs can bring back audible echo residue in speaker+mic
|
||||
* (no headset) setups - some users get a cleaner result with it off. */
|
||||
autoGainControl?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,6 +66,7 @@ export class MicCapture {
|
||||
private deviceId?: string;
|
||||
private echoCancellation: boolean;
|
||||
private noiseSuppression: boolean;
|
||||
private autoGainControl: boolean;
|
||||
private context: AudioContext;
|
||||
threshold: number;
|
||||
hangoverSeconds: number;
|
||||
@@ -75,6 +81,7 @@ export class MicCapture {
|
||||
this.deviceId = options.deviceId;
|
||||
this.echoCancellation = options.echoCancellation ?? true;
|
||||
this.noiseSuppression = options.noiseSuppression ?? true;
|
||||
this.autoGainControl = options.autoGainControl ?? true;
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
@@ -84,8 +91,15 @@ export class MicCapture {
|
||||
this.stream = await navigator.mediaDevices.getUserMedia({
|
||||
audio: {
|
||||
channelCount: 1,
|
||||
// Requesting the pipeline's own rate (rather than leaving it to the
|
||||
// device/OS default) avoids an extra internal resampling step ahead
|
||||
// of the browser's own echo canceller - standard constraint, honored
|
||||
// by both Chromium and Firefox, "ideal" so it's not fatal if a device
|
||||
// genuinely can't provide it.
|
||||
sampleRate: { ideal: SAMPLE_RATE },
|
||||
echoCancellation: this.echoCancellation,
|
||||
noiseSuppression: this.noiseSuppression,
|
||||
autoGainControl: this.autoGainControl,
|
||||
...(this.deviceId ? { deviceId: { exact: this.deviceId } } : {}),
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user