feat(voice): configurable user voice-recognition time (bargeInMs, default 700ms)

Expose the barge-in sustained-speech threshold as a dashboard bot setting
"유저 음성 인식 시간" (ms). Server clamps 0..5000, persists via state_store,
and the bot reads it each report round-trip; WSAI_BARGE_IN_MS/700 stays the
fallback default.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-08-27 11:35:01 +09:00
parent d5501d0b8a
commit 0e4e7c6bb2
3 changed files with 41 additions and 4 deletions

View File

@@ -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 });