From 5d17e2e9ac88d0b11c554461f0ab9aa1ab70d3b4 Mon Sep 17 00:00:00 2001 From: imbytecat Date: Sun, 1 Mar 2026 04:35:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=89=E5=8D=93=20C?= =?UTF-8?q?hrome=20=E6=97=A0=E9=9F=B3=E9=A2=91=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=BC=BA=E5=88=B6=2016kHz=20=E9=87=87?= =?UTF-8?q?=E6=A0=B7=E7=8E=87=EF=BC=8C=E6=B7=BB=E5=8A=A0=20AudioContext=20?= =?UTF-8?q?resume?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/app.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web/app.js b/web/app.js index 6e19df9..4f3d574 100644 --- a/web/app.js +++ b/web/app.js @@ -173,9 +173,12 @@ // ── Audio pipeline ── async function initAudio() { if (state.audioCtx) return; - const audioCtx = new (window.AudioContext || window.webkitAudioContext)({ - sampleRate: TARGET_SAMPLE_RATE, // Request 16kHz directly (Chrome supports) - }); + // Use device native sample rate — we resample to 16kHz in software + const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); + // Chrome requires resume() after user gesture + if (audioCtx.state === "suspended") { + await audioCtx.resume(); + } await audioCtx.audioWorklet.addModule("audio-processor.js"); state.audioCtx = audioCtx; } @@ -183,6 +186,10 @@ if (state.recording) return; try { await initAudio(); + // Ensure AudioContext is running (may suspend between recordings) + if (state.audioCtx.state === "suspended") { + await state.audioCtx.resume(); + } const stream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true, channelCount: 1 }, });