feat: 17s active listen window after command — no prefix needed for follow-ups

This commit is contained in:
2026-05-31 16:38:27 +00:00
parent ab624638a7
commit b0a6f2d2e9
+16 -9
View File
@@ -919,10 +919,12 @@ const IDLE_RELOAD_MS = 5 * 60 * 1000; // 5 min inactivity → full reload
let voiceMode = false; // true = JARVIS awake (listening for commands)
let voiceMuted = false; // true = awake but mic muted
let voiceLastCmd = 0;
const VOICE_SLEEP_MS = 30 * 60 * 1000; // 30 min voice inactivity → sleep
const VOICE_SLEEP_MS = 30 * 60 * 1000; // 30 min voice inactivity → sleep
const VOICE_ACTIVE_MS = 17000; // 17s active window after each command
let voiceActive = 0; // timestamp of last issued command
// Phase 1: full phrase required to wake from sleep
const WAKE_PHRASES = ["wake up jarvis", "daddy's home", "wake up, jarvis", "daddys home"];
// Phase 2: command prefix when awake — "jarvis <command>"
// Phase 2: command prefix — "jarvis <command>"; then 17s free-listen window
const CMD_PREFIX = 'jarvis';
const FACE_MODEL_URL = 'https://cdn.jsdelivr.net/gh/justadudewhohacks/face-api.js@0.22.2/weights';
@@ -1747,14 +1749,19 @@ function initVoice() {
// Sleeping — full wake phrase required
if (WAKE_PHRASES.some(p => lc.includes(p))) enterVoiceMode();
} else if (!voiceMuted) {
// Awake — must start with "Jarvis" to trigger a command
voiceLastCmd = Date.now(); // any speech resets inactivity timer
// Awake — "Jarvis <cmd>" triggers command; active window allows free speech
voiceLastCmd = Date.now(); // any detected speech resets 30-min sleep timer
const inWindow = voiceActive > 0 && (Date.now() - voiceActive) < VOICE_ACTIVE_MS;
let cmd = null;
if (lc.startsWith(CMD_PREFIX)) {
const cmd = transcript.substring(CMD_PREFIX.length).trim();
if (cmd) {
document.getElementById('textInput').value = cmd;
sendMessage();
}
cmd = transcript.substring(CMD_PREFIX.length).trim();
} else if (inWindow) {
cmd = transcript; // active window: no prefix needed
}
if (cmd) {
voiceActive = Date.now(); // reset 17s window
document.getElementById('textInput').value = cmd;
sendMessage();
}
}
};