diff --git a/web/src/App.tsx b/web/src/App.tsx index 5806cd1..f765e66 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1190,6 +1190,16 @@ function App() { socketRef.current?.send(JSON.stringify({ type: "setInputMuted", muted: !inputMutedRef.current })); }; + // Enable the mic automatically on page load (voice activation still gates + // what's actually sent) instead of requiring an explicit click every time. + const autoMicAttemptedRef = useRef(false); + useEffect(() => { + if (autoMicAttemptedRef.current) return; + autoMicAttemptedRef.current = true; + void handleToggleMic(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + const handleToggleOutputMuted = () => { socketRef.current?.send(JSON.stringify({ type: "setOutputMuted", muted: !outputMutedRef.current })); }; diff --git a/web/src/voice.ts b/web/src/voice.ts index 963c0fc..f976b52 100644 --- a/web/src/voice.ts +++ b/web/src/voice.ts @@ -61,6 +61,10 @@ export class MicCapture { this.stream = await navigator.mediaDevices.getUserMedia({ audio: { channelCount: 1, echoCancellation: true, noiseSuppression: true }, }); + // Granting the permission prompt counts as a user gesture, so this can + // succeed even when start() was triggered automatically on page load, + // before the AudioContext would otherwise be allowed to leave "suspended". + if (this.context.state === "suspended") await this.context.resume(); this.source = this.context.createMediaStreamSource(this.stream); this.processor = this.context.createScriptProcessor(2048, 1, 1); this.processor.onaudioprocess = (event) => {