diff --git a/dave/bot.mjs b/dave/bot.mjs index 42493ce..a056768 100644 --- a/dave/bot.mjs +++ b/dave/bot.mjs @@ -180,8 +180,13 @@ let listsByGuild = {}; // guildId -> {whitelistUsers, blacklistUsers, let botSettings = { bargeIn: true }; // behaviour toggles from the dashboard // Barge-in only fires when the Discord "speaking" (green ring) stays on for at // least this long — a brief blip (keyboard click, cough) shouldn't cut the bot -// off, but a genuine ~0.7s of speech should. Tunable via WSAI_BARGE_IN_MS. +// off, but a genuine ~0.7s of speech should. The dashboard's "유저 음성 인식 시간" +// (botSettings.bargeInMs) wins when set; WSAI_BARGE_IN_MS / 700 is the fallback. const BARGE_IN_MS = Number(process.env.WSAI_BARGE_IN_MS || 700); +function bargeInMs() { + const v = Number(botSettings.bargeInMs); + return Number.isFinite(v) && v >= 0 ? v : BARGE_IN_MS; +} const bargeTimers = new Map(); // userId -> pending stop timer // Attach the bot's audio player (so it can speak) to a fresh connection. @@ -214,7 +219,7 @@ function setupReceiver(connection) { bargeTimers.set(userId, setTimeout(() => { bargeTimers.delete(userId); try { voicePlayer.stop(true); } catch {} - }, BARGE_IN_MS)); + }, bargeInMs())); } activeSubs.add(userId); if (!perUser.has(userId)) perUser.set(userId, { opusPackets: 0, pcmFrames: 0 }); diff --git a/wsai/bot_control.py b/wsai/bot_control.py index fa05463..03a3372 100644 --- a/wsai/bot_control.py +++ b/wsai/bot_control.py @@ -37,7 +37,13 @@ class BotControl: self._lists: dict[str, dict[str, Any]] = st.get("lists") or {} # Bot behaviour settings the dashboard toggles and the bot reads on each # report. bargeIn: stop the bot's current TTS the moment a user speaks. - self._settings: dict[str, Any] = {"bargeIn": True, **(st.get("botSettings") or {})} + # bargeInMs: how long (ms) a user must keep speaking before that barge-in + # fires — the "유저 음성 인식 시간" the dashboard exposes (default 700). + self._settings: dict[str, Any] = { + "bargeIn": True, + "bargeInMs": 700, + **(st.get("botSettings") or {}), + } # -- bot behaviour settings ------------------------------------------ # def get_settings(self) -> dict[str, Any]: @@ -48,6 +54,13 @@ class BotControl: with self._lock: if "bargeIn" in data: self._settings["bargeIn"] = bool(data["bargeIn"]) + if "bargeInMs" in data: + try: + ms = int(data["bargeInMs"]) + except (TypeError, ValueError): + ms = 700 + # Keep it sane: 0ms = instant, cap at 5s so a typo can't wedge it. + self._settings["bargeInMs"] = max(0, min(5000, ms)) out = dict(self._settings) from . import state_store state_store.patch("botSettings", out) diff --git a/wsai/dashboard.py b/wsai/dashboard.py index 2a91864..60e0f33 100644 --- a/wsai/dashboard.py +++ b/wsai/dashboard.py @@ -1162,6 +1162,10 @@ PAGE = r"""