feat: two-phase voice — full wake phrase to activate, Jarvis prefix to command

This commit is contained in:
2026-05-31 16:36:48 +00:00
parent 01c6cfe96b
commit ab624638a7
+15 -7
View File
@@ -920,7 +920,10 @@ let voiceMode = false; // true = JARVIS awake (listening for commands)
let voiceMuted = false; // true = awake but mic muted let voiceMuted = false; // true = awake but mic muted
let voiceLastCmd = 0; 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 WAKE_WORDS = ['jarvis', 'hey jarvis', "daddy's home", 'wake up']; // 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>"
const CMD_PREFIX = 'jarvis';
const FACE_MODEL_URL = 'https://cdn.jsdelivr.net/gh/justadudewhohacks/face-api.js@0.22.2/weights'; const FACE_MODEL_URL = 'https://cdn.jsdelivr.net/gh/justadudewhohacks/face-api.js@0.22.2/weights';
// ── INIT ───────────────────────────────────────────────────────────── // ── INIT ─────────────────────────────────────────────────────────────
@@ -1739,16 +1742,21 @@ function initVoice() {
if (!result.isFinal) return; if (!result.isFinal) return;
const transcript = result[0].transcript.trim(); const transcript = result[0].transcript.trim();
if (!transcript) return; if (!transcript) return;
if (!voiceMode) {
// Sleeping — check for wake word
const lc = transcript.toLowerCase(); const lc = transcript.toLowerCase();
if (WAKE_WORDS.some(w => lc.includes(w))) enterVoiceMode(); if (!voiceMode) {
// Sleeping — full wake phrase required
if (WAKE_PHRASES.some(p => lc.includes(p))) enterVoiceMode();
} else if (!voiceMuted) { } else if (!voiceMuted) {
// Awake — process as command // Awake — must start with "Jarvis" to trigger a command
voiceLastCmd = Date.now(); voiceLastCmd = Date.now(); // any speech resets inactivity timer
document.getElementById('textInput').value = transcript; if (lc.startsWith(CMD_PREFIX)) {
const cmd = transcript.substring(CMD_PREFIX.length).trim();
if (cmd) {
document.getElementById('textInput').value = cmd;
sendMessage(); sendMessage();
} }
}
}
}; };
recognition.onend = () => { recognition.onend = () => {