From 170a01948c2539d6a035c4be988ad0fb64d12090 Mon Sep 17 00:00:00 2001 From: jimmy Date: Tue, 17 Nov 2026 16:49:01 +1300 Subject: [PATCH] audio ui: input level bar on a dB scale (-80 to 0 dB) Co-Authored-By: Claude Haiku 5.5 --- web/static/audio.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/web/static/audio.js b/web/static/audio.js index 0a2b5ee..220903c 100644 --- a/web/static/audio.js +++ b/web/static/audio.js @@ -293,8 +293,14 @@ return `${pct}% (${dbText} dB)`; } + // level is linear RMS (1.0 = full scale). Show it on a dB scale: -80 dB → 0%, 0 dB → 100%, + // so room noise and speech both move the bar. function updateInputLevelDisplay(level) { - const pct = Number.isFinite(level) ? Math.round(Math.min(1, Math.max(0, level)) * 100) : 0; + let pct = 0; + if (Number.isFinite(level) && level > 0) { + const db = 20 * Math.log10(level); + pct = Math.round(Math.min(1, Math.max(0, (db + 80) / 80)) * 100); + } const bar = el("audio-input-level-bar"); const meter = el("audio-modal")?.querySelector(".audio-input-level-meter"); if (bar) bar.style.width = `${pct}%`; @@ -719,15 +725,14 @@ function bind() { const modal = el("audio-modal"); const openBtn = el("audio-btn"); - const closeBtn = el("audio-close-btn"); const startBtn = el("audio-start-btn"); const stopBtn = el("audio-stop-btn"); const resetBtn = el("audio-reset-btn"); const refreshBtn = el("audio-refresh-btn"); if (!modal || !openBtn) return; - openBtn.addEventListener("click", async () => { - modal.classList.add("active"); + // The Audio tab of Settings: the page's Audio button (kept hidden) opens Settings on it + const showTab = async () => { try { await refreshDevices(); } catch (e) { @@ -735,12 +740,11 @@ } await loadServerAudioUiFields(); setResetDetectorEnabled(audioDetectorRunning); + }; + openBtn.addEventListener("click", () => window.openSettingsTab && window.openSettingsTab("audio")); + document.addEventListener("settings-tab", (e) => { + if (e.detail === "audio") showTab(); }); - if (closeBtn) { - closeBtn.addEventListener("click", () => { - modal.classList.remove("active"); - }); - } if (startBtn) { startBtn.addEventListener("click", async () => { const picked = getSelectedDeviceId();