import * as dotenv from 'dotenv'; import { exec } from 'child_process'; import readline from 'readline'; import { DateTime } from 'luxon'; import open from 'open'; // Load environment variables dotenv.config(); class Jarvis { constructor() { this.voices = []; // Placeholder for voice options this.rate = 150; // Speech speed } speak(text) { console.log(`JARVIS: ${text}`); exec(`say "${text}"`); // Using macOS say command for speech } listen() { const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); return new Promise((resolve) => { rl.question('Listening... ', (command) => { console.log(`YOU: ${command}`); rl.close(); resolve(command.toLowerCase()); }); }); } greet() { const hour = DateTime.now().hour; if (hour >= 5 && hour < 12) { this.speak("Good morning!"); } else if (hour >= 12 && hour < 18) { this.speak("Good afternoon!"); } else { this.speak("Good evening!"); } } async executeCommand(command) { if (command.includes('time')) { const currentTime = DateTime.now().toFormat('hh:mm a'); this.speak(`The current time is ${currentTime}`); } else if (command.includes('open youtube')) { this.speak("Opening YouTube"); await open("https://youtube.com"); } else if (command.includes('search web')) { const query = command.replace("search web", "").trim(); await open(`https://google.com/search?q=${query}`); } else if (command.includes('exit') || command.includes('bye')) { this.speak("Goodbye!"); process.exit(); } } } (async () => { const jarvis = new Jarvis(); jarvis.greet(); jarvis.speak("How can I assist you today?"); while (true) { const command = await jarvis.listen(); if (command) { await jarvis.executeCommand(command); } } })();

Comments

Popular posts from this blog