mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
feat: two-phase voice — full wake phrase to activate, Jarvis prefix to command
This commit is contained in:
+16
-8
@@ -920,7 +920,10 @@ 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 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';
|
||||
|
||||
// ── INIT ─────────────────────────────────────────────────────────────
|
||||
@@ -1739,15 +1742,20 @@ function initVoice() {
|
||||
if (!result.isFinal) return;
|
||||
const transcript = result[0].transcript.trim();
|
||||
if (!transcript) return;
|
||||
const lc = transcript.toLowerCase();
|
||||
if (!voiceMode) {
|
||||
// Sleeping — check for wake word
|
||||
const lc = transcript.toLowerCase();
|
||||
if (WAKE_WORDS.some(w => lc.includes(w))) enterVoiceMode();
|
||||
// Sleeping — full wake phrase required
|
||||
if (WAKE_PHRASES.some(p => lc.includes(p))) enterVoiceMode();
|
||||
} else if (!voiceMuted) {
|
||||
// Awake — process as command
|
||||
voiceLastCmd = Date.now();
|
||||
document.getElementById('textInput').value = transcript;
|
||||
sendMessage();
|
||||
// Awake — must start with "Jarvis" to trigger a command
|
||||
voiceLastCmd = Date.now(); // any speech resets inactivity timer
|
||||
if (lc.startsWith(CMD_PREFIX)) {
|
||||
const cmd = transcript.substring(CMD_PREFIX.length).trim();
|
||||
if (cmd) {
|
||||
document.getElementById('textInput').value = cmd;
|
||||
sendMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user