File size: 43,965 Bytes
da9913f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aron - Your AI Task Assistant</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.pulse-animation {
animation: pulse 2s infinite;
}
.typing-indicator::after {
content: '...';
display: inline-block;
width: 0;
overflow: hidden;
vertical-align: bottom;
animation: ellipsis steps(4,end) 1.5s infinite;
}
@keyframes ellipsis {
to { width: 1.25em; }
}
.message-enter {
animation: messageEnter 0.3s ease-out;
}
@keyframes messageEnter {
from { transform: translateY(20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.task-reminder {
border-left: 4px solid #3b82f6;
background-color: rgba(59, 130, 246, 0.1);
}
.wake-word-active {
box-shadow: 0 0 20px rgba(59, 130, 246, 0.7);
}
.voice-wave {
position: relative;
}
.voice-wave::before {
content: "";
position: absolute;
width: 100%;
height: 100%;
border-radius: 9999px;
background: rgba(59, 130, 246, 0.3);
animation: voiceWave 1.5s infinite;
z-index: -1;
}
@keyframes voiceWave {
0% { transform: scale(1); opacity: 1; }
100% { transform: scale(1.5); opacity: 0; }
}
</style>
</head>
<body class="bg-gray-100 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<!-- Header -->
<header class="bg-gradient-to-r from-blue-600 to-indigo-700 text-white rounded-xl shadow-lg p-6 mb-8">
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold">Aron</h1>
<p class="text-blue-100 mt-1">Your intelligent voice assistant for task management</p>
</div>
<div id="wakeWordIndicator" class="w-16 h-16 bg-white rounded-full flex items-center justify-center shadow-md transition-all duration-300">
<i class="fas fa-robot text-3xl text-blue-600"></i>
</div>
</div>
</header>
<!-- Main Content -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Left Panel - User Info and Task Form -->
<div class="lg:col-span-1 space-y-6">
<!-- User Profile -->
<div class="bg-white rounded-xl shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Your Profile</h2>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Your Name</label>
<input type="text" id="userName" placeholder="Enter your name"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Aron's Voice</label>
<select id="voiceSelect" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
<option value="default">Default</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<button id="saveProfile" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-lg transition duration-200">
Save Profile
</button>
</div>
</div>
<!-- Add Task Form -->
<div class="bg-white rounded-xl shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Add New Task</h2>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Task Name</label>
<input type="text" id="taskName" placeholder="What needs to be done?"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Task Time</label>
<input type="time" id="taskTime"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Task Date</label>
<input type="date" id="taskDate"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Priority</label>
<select id="taskPriority" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
<option value="low">Low</option>
<option value="medium" selected>Medium</option>
<option value="high">High</option>
</select>
</div>
<button id="addTask" class="w-full bg-green-600 hover:bg-green-700 text-white font-medium py-2 px-4 rounded-lg transition duration-200">
Add Task
</button>
</div>
</div>
</div>
<!-- Right Panel - Chat Interface and Task List -->
<div class="lg:col-span-2 space-y-6">
<!-- Chat Interface -->
<div class="bg-white rounded-xl shadow-md p-6 h-96 flex flex-col">
<div class="flex items-center justify-between border-b pb-3 mb-4">
<h2 class="text-xl font-semibold text-gray-800">Aron Assistant</h2>
<div class="flex space-x-2">
<button id="voiceToggle" class="bg-blue-100 hover:bg-blue-200 text-blue-800 p-2 rounded-full transition duration-200">
<i class="fas fa-microphone"></i>
</button>
<button id="clearChat" class="bg-gray-100 hover:bg-gray-200 text-gray-800 p-2 rounded-full transition duration-200">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</div>
<!-- Chat Messages -->
<div id="chatMessages" class="flex-1 overflow-y-auto space-y-3 pr-2">
<div class="message-enter bg-blue-50 rounded-lg p-4 max-w-xs">
<p class="text-gray-800">Hello! I'm Aron, your AI task assistant. You can say "Hey Aron" to wake me up or ask about your tasks.</p>
</div>
</div>
<!-- Chat Input -->
<div class="mt-4 flex">
<input type="text" id="chatInput" placeholder="Type your message here..."
class="flex-1 px-4 py-2 border border-gray-300 rounded-l-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
<button id="sendMessage" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-r-lg transition duration-200">
<i class="fas fa-paper-plane"></i>
</button>
</div>
</div>
<!-- Task List -->
<div class="bg-white rounded-xl shadow-md p-6">
<div class="flex items-center justify-between border-b pb-3 mb-4">
<h2 class="text-xl font-semibold text-gray-800">Your Scheduled Tasks</h2>
<div class="text-sm text-gray-500" id="currentDateTime"></div>
</div>
<div id="taskList" class="space-y-3">
<div class="text-center py-8 text-gray-500">
<i class="fas fa-tasks text-4xl mb-2"></i>
<p>No tasks scheduled yet. Add your first task!</p>
</div>
</div>
</div>
</div>
</div>
<!-- Voice Assistant Status -->
<div id="voiceStatus" class="fixed bottom-6 right-6 bg-blue-600 text-white rounded-full p-4 shadow-xl hidden">
<div class="flex items-center space-x-2">
<i class="fas fa-microphone"></i>
<span>Listening...</span>
</div>
</div>
<!-- Floating Voice Interaction Button -->
<button id="voiceInteractionBtn" class="fixed bottom-6 left-6 w-16 h-16 bg-blue-600 text-white rounded-full flex items-center justify-center shadow-xl hover:bg-blue-700 transition duration-200 voice-wave">
<i class="fas fa-microphone text-2xl"></i>
</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// DOM Elements
const userNameInput = document.getElementById('userName');
const voiceSelect = document.getElementById('voiceSelect');
const saveProfileBtn = document.getElementById('saveProfile');
const taskNameInput = document.getElementById('taskName');
const taskTimeInput = document.getElementById('taskTime');
const taskDateInput = document.getElementById('taskDate');
const taskPrioritySelect = document.getElementById('taskPriority');
const addTaskBtn = document.getElementById('addTask');
const chatMessages = document.getElementById('chatMessages');
const chatInput = document.getElementById('chatInput');
const sendMessageBtn = document.getElementById('sendMessage');
const voiceToggleBtn = document.getElementById('voiceToggle');
const clearChatBtn = document.getElementById('clearChat');
const taskList = document.getElementById('taskList');
const currentDateTime = document.getElementById('currentDateTime');
const voiceStatus = document.getElementById('voiceStatus');
const wakeWordIndicator = document.getElementById('wakeWordIndicator');
const voiceInteractionBtn = document.getElementById('voiceInteractionBtn');
// Speech Synthesis
const synth = window.speechSynthesis;
let voices = [];
let selectedVoice = null;
let isListening = false;
let isWakeWordDetectionActive = false;
let recognition;
let continuousRecognition;
let userName = '';
let tasks = [];
let scheduledReminders = {};
// Initialize the app
initApp();
function initApp() {
// Load user data from localStorage
loadUserData();
// Update current date and time
updateDateTime();
setInterval(updateDateTime, 1000);
// Check for task reminders every minute
setInterval(checkTaskReminders, 60000);
// Initialize Web Speech API voices
initVoices();
// Initialize voice recognition if available
initVoiceRecognition();
initWakeWordDetection();
// Event Listeners
saveProfileBtn.addEventListener('click', saveUserProfile);
addTaskBtn.addEventListener('click', addNewTask);
sendMessageBtn.addEventListener('click', sendChatMessage);
chatInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') sendChatMessage();
});
voiceToggleBtn.addEventListener('click', toggleVoiceRecognition);
clearChatBtn.addEventListener('click', clearChat);
voiceInteractionBtn.addEventListener('click', toggleWakeWordDetection);
// Check for any immediate reminders on load
checkTaskReminders();
// Initial greeting
setTimeout(() => {
const greeting = userName
? `Hello ${userName}, I'm Aron. You can say "Hey Aron" to wake me up or ask about your tasks.`
: "Hello, I'm Aron, your AI task assistant. Please set your name in the profile section. You can say 'Hey Aron' to wake me up.";
addChatMessage('assistant', greeting);
speak(greeting);
}, 1000);
}
function loadUserData() {
const savedUser = localStorage.getItem('taskMasterUser');
if (savedUser) {
const userData = JSON.parse(savedUser);
userNameInput.value = userData.name || '';
voiceSelect.value = userData.voice || 'default';
userName = userData.name || '';
// Load tasks
const savedTasks = localStorage.getItem('taskMasterTasks');
if (savedTasks) {
tasks = JSON.parse(savedTasks);
renderTaskList();
}
}
}
function saveUserProfile() {
const name = userNameInput.value.trim();
const voicePref = voiceSelect.value;
if (name) {
userName = name;
localStorage.setItem('taskMasterUser', JSON.stringify({
name: name,
voice: voicePref
}));
addChatMessage('assistant', `Profile saved successfully, ${name}. How can I assist you today?`);
speak(`Profile saved successfully, ${name}. How can I assist you today?`);
updateSelectedVoice();
} else {
addChatMessage('assistant', 'Please enter your name to save your profile.');
speak('Please enter your name to save your profile.');
}
}
function addNewTask() {
const name = taskNameInput.value.trim();
const time = taskTimeInput.value;
const date = taskDateInput.value;
const priority = taskPrioritySelect.value;
if (!name) {
addChatMessage('assistant', 'Please enter a task name.');
speak('Please enter a task name.');
return;
}
if (!time) {
addChatMessage('assistant', 'Please select a time for your task.');
speak('Please select a time for your task.');
return;
}
if (!date) {
addChatMessage('assistant', 'Please select a date for your task.');
speak('Please select a date for your task.');
return;
}
const taskDate = new Date(`${date}T${time}`);
const now = new Date();
if (taskDate <= now) {
addChatMessage('assistant', 'Please select a future time for your task.');
speak('Please select a future time for your task.');
return;
}
const task = {
id: Date.now(),
name: name,
date: date,
time: time,
priority: priority,
completed: false,
createdAt: new Date().toISOString()
};
tasks.push(task);
saveTasks();
renderTaskList();
// Clear form
taskNameInput.value = '';
taskTimeInput.value = '';
taskDateInput.value = '';
taskPrioritySelect.value = 'medium';
// Schedule reminder
scheduleTaskReminder(task);
addChatMessage('assistant', `Task "${name}" has been added for ${formatDateTime(taskDate)}. I'll remind you when it's time.`);
speak(`Task "${name}" has been added for ${formatDateTime(taskDate)}. I'll remind you when it's time.`);
}
function scheduleTaskReminder(task) {
const taskDate = new Date(`${task.date}T${task.time}`);
const now = new Date();
const timeUntilTask = taskDate - now;
// Clear any existing reminder for this task
if (scheduledReminders[task.id]) {
clearTimeout(scheduledReminders[task.id]);
}
if (timeUntilTask > 0) {
scheduledReminders[task.id] = setTimeout(() => {
remindUserAboutTask(task);
}, timeUntilTask);
}
}
function remindUserAboutTask(task) {
if (userName) {
const message = `${userName}, it's time for your scheduled task: "${task.name}". This is a ${task.priority} priority task. Would you like me to help you with anything related to this?`;
addChatMessage('assistant', message, true);
speak(message);
} else {
const message = `Reminder: It's time for your task "${task.name}". This is a ${task.priority} priority task. Would you like me to help you with anything related to this?`;
addChatMessage('assistant', message, true);
speak(message);
}
// Mark task as completed (for demo purposes)
task.completed = true;
saveTasks();
renderTaskList();
}
function checkTaskReminders() {
const now = new Date();
tasks.forEach(task => {
if (!task.completed) {
const taskDate = new Date(`${task.date}T${task.time}`);
const timeDiff = taskDate - now;
// If task time is within the next 5 minutes
if (timeDiff > 0 && timeDiff <= 300000) {
const minutesLeft = Math.floor(timeDiff / 60000);
const message = `Just a heads up ${userName ? userName + ',' : ''} your task "${task.name}" is coming up in ${minutesLeft} minute${minutesLeft !== 1 ? 's' : ''}. Would you like to prepare anything in advance?`;
addChatMessage('assistant', message, true);
speak(message);
}
}
});
}
function renderTaskList() {
if (tasks.length === 0) {
taskList.innerHTML = `
<div class="text-center py-8 text-gray-500">
<i class="fas fa-tasks text-4xl mb-2"></i>
<p>No tasks scheduled yet. Add your first task!</p>
</div>
`;
return;
}
// Sort tasks by date and time (soonest first)
const sortedTasks = [...tasks].sort((a, b) => {
return new Date(`${a.date}T${a.time}`) - new Date(`${b.date}T${b.time}`);
});
let html = '';
sortedTasks.forEach(task => {
const taskDate = new Date(`${task.date}T${task.time}`);
const now = new Date();
const isPastDue = taskDate < now && !task.completed;
html += `
<div class="border rounded-lg p-4 ${isPastDue ? 'border-red-300 bg-red-50' : 'border-gray-200'} ${task.completed ? 'opacity-70' : ''}">
<div class="flex justify-between items-start">
<div>
<h3 class="font-medium ${task.completed ? 'line-through text-gray-500' : 'text-gray-800'}">${task.name}</h3>
<p class="text-sm ${task.completed ? 'text-gray-400' : 'text-gray-600'}">${formatDateTime(taskDate)}</p>
</div>
<div class="flex items-center space-x-2">
<span class="px-2 py-1 text-xs rounded-full ${
task.priority === 'high' ? 'bg-red-100 text-red-800' :
task.priority === 'medium' ? 'bg-yellow-100 text-yellow-800' :
'bg-green-100 text-green-800'
}">
${task.priority}
</span>
<button onclick="completeTask(${task.id})" class="text-green-600 hover:text-green-800">
<i class="fas fa-check"></i>
</button>
<button onclick="deleteTask(${task.id})" class="text-red-600 hover:text-red-800">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</div>
${isPastDue && !task.completed ? '<p class="text-xs text-red-600 mt-2">Past due</p>' : ''}
</div>
`;
});
taskList.innerHTML = html;
}
function completeTask(taskId) {
const taskIndex = tasks.findIndex(t => t.id === taskId);
if (taskIndex !== -1) {
tasks[taskIndex].completed = true;
saveTasks();
renderTaskList();
const task = tasks[taskIndex];
const message = `Great job completing your task "${task.name}"! ${userName ? userName + ',' : ''} would you like to add any notes about how it went?`;
addChatMessage('assistant', message);
speak(message);
}
}
function deleteTask(taskId) {
tasks = tasks.filter(t => t.id !== taskId);
saveTasks();
renderTaskList();
// Clear any scheduled reminder
if (scheduledReminders[taskId]) {
clearTimeout(scheduledReminders[taskId]);
delete scheduledReminders[taskId];
}
addChatMessage('assistant', 'Task has been deleted. Is there anything else you\'d like me to help with?');
speak('Task has been deleted. Is there anything else you\'d like me to help with?');
}
function saveTasks() {
localStorage.setItem('taskMasterTasks', JSON.stringify(tasks));
}
function updateDateTime() {
const now = new Date();
currentDateTime.textContent = now.toLocaleString('en-US', {
weekday: 'long',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
}
function formatDateTime(date) {
return date.toLocaleString('en-US', {
weekday: 'short',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
}
function initVoices() {
// Chrome loads voices asynchronously
synth.onvoiceschanged = function() {
voices = synth.getVoices();
// Try to find a suitable voice based on user preference
updateSelectedVoice();
};
// Get voices immediately if already loaded
voices = synth.getVoices();
if (voices.length > 0) {
updateSelectedVoice();
}
}
function updateSelectedVoice() {
const voicePref = voiceSelect.value;
if (voicePref === 'male') {
// Try to find a male voice
selectedVoice = voices.find(v => v.name.includes('Male')) ||
voices.find(v => v.lang.includes('en')) ||
voices[0];
} else if (voicePref === 'female') {
// Try to find a female voice
selectedVoice = voices.find(v => v.name.includes('Female')) ||
voices.find(v => v.lang.includes('en')) ||
voices[0];
} else {
// Default voice
selectedVoice = voices.find(v => v.lang.includes('en')) || voices[0];
}
}
function speak(text) {
if (!synth || !selectedVoice) return;
const utterance = new SpeechSynthesisUtterance(text);
utterance.voice = selectedVoice;
utterance.rate = 0.9;
utterance.pitch = 1;
synth.speak(utterance);
}
function initVoiceRecognition() {
try {
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
if (SpeechRecognition) {
recognition = new SpeechRecognition();
recognition.continuous = false;
recognition.interimResults = false;
recognition.lang = 'en-US';
recognition.onstart = function() {
isListening = true;
voiceStatus.classList.remove('hidden');
voiceToggleBtn.innerHTML = '<i class="fas fa-microphone-slash"></i>';
voiceToggleBtn.classList.remove('bg-blue-100', 'text-blue-800');
voiceToggleBtn.classList.add('bg-red-100', 'text-red-800');
};
recognition.onend = function() {
isListening = false;
voiceStatus.classList.add('hidden');
voiceToggleBtn.innerHTML = '<i class="fas fa-microphone"></i>';
voiceToggleBtn.classList.remove('bg-red-100', 'text-red-800');
voiceToggleBtn.classList.add('bg-blue-100', 'text-blue-800');
};
recognition.onresult = function(event) {
const transcript = event.results[0][0].transcript;
chatInput.value = transcript;
sendChatMessage();
};
recognition.onerror = function(event) {
console.error('Speech recognition error', event.error);
addChatMessage('assistant', 'Sorry, I didn\'t catch that. Could you try again?');
speak('Sorry, I didn\'t catch that. Could you try again?');
};
} else {
voiceToggleBtn.disabled = true;
voiceToggleBtn.title = 'Voice recognition not supported in your browser';
}
} catch (e) {
console.error('Error initializing voice recognition:', e);
voiceToggleBtn.disabled = true;
voiceToggleBtn.title = 'Voice recognition not available';
}
}
function initWakeWordDetection() {
try {
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
if (SpeechRecognition) {
continuousRecognition = new SpeechRecognition();
continuousRecognition.continuous = true;
continuousRecognition.interimResults = true;
continuousRecognition.lang = 'en-US';
continuousRecognition.onresult = function(event) {
if (!isWakeWordDetectionActive) return;
let interimTranscript = '';
let finalTranscript = '';
for (let i = event.resultIndex; i < event.results.length; i++) {
const transcript = event.results[i][0].transcript;
if (event.results[i].isFinal) {
finalTranscript += transcript;
} else {
interimTranscript += transcript;
}
}
// Check for wake words in both interim and final transcripts
const combinedTranscript = (interimTranscript + ' ' + finalTranscript).toLowerCase();
if (combinedTranscript.includes('hey aron') ||
combinedTranscript.includes('hello aron') ||
combinedTranscript.includes('hi aron')) {
// Visual feedback
wakeWordIndicator.classList.add('wake-word-active');
setTimeout(() => {
wakeWordIndicator.classList.remove('wake-word-active');
}, 1000);
// Respond to wake word
if (!isListening) {
const wakeResponse = userName
? `Yes ${userName}? How can I help you?`
: "Yes? How can I help you?";
addChatMessage('assistant', wakeResponse);
speak(wakeResponse);
// Start normal recognition
setTimeout(() => {
if (recognition) {
try {
recognition.start();
} catch (e) {
console.error('Error starting recognition:', e);
}
}
}, 500);
}
}
};
continuousRecognition.onerror = function(event) {
console.error('Wake word detection error:', event.error);
};
}
} catch (e) {
console.error('Error initializing wake word detection:', e);
}
}
function toggleWakeWordDetection() {
if (!continuousRecognition) {
addChatMessage('assistant', 'Wake word detection is not supported in your browser.');
speak('Wake word detection is not supported in your browser.');
return;
}
isWakeWordDetectionActive = !isWakeWordDetectionActive;
if (isWakeWordDetectionActive) {
try {
continuousRecognition.start();
voiceInteractionBtn.classList.add('bg-blue-700');
voiceInteractionBtn.innerHTML = '<i class="fas fa-microphone-slash text-2xl"></i>';
addChatMessage('assistant', 'I\'m now listening for "Hey Aron". Try saying it!');
speak('I\'m now listening for "Hey Aron". Try saying it!');
} catch (e) {
console.error('Error starting continuous recognition:', e);
isWakeWordDetectionActive = false;
}
} else {
continuousRecognition.stop();
voiceInteractionBtn.classList.remove('bg-blue-700');
voiceInteractionBtn.innerHTML = '<i class="fas fa-microphone text-2xl"></i>';
addChatMessage('assistant', 'Wake word detection turned off.');
speak('Wake word detection turned off.');
}
}
function toggleVoiceRecognition() {
if (!recognition) return;
if (isListening) {
recognition.stop();
} else {
try {
recognition.start();
addChatMessage('assistant', 'I\'m listening...');
} catch (e) {
console.error('Error starting recognition:', e);
addChatMessage('assistant', 'Sorry, I couldn\'t start listening. Please try again.');
speak('Sorry, I couldn\'t start listening. Please try again.');
}
}
}
function sendChatMessage() {
const message = chatInput.value.trim();
if (!message) return;
addChatMessage('user', message);
chatInput.value = '';
// Show typing indicator
const typingIndicator = document.createElement('div');
typingIndicator.className = 'bg-blue-50 rounded-lg p-4 max-w-xs';
typingIndicator.innerHTML = '<p class="text-gray-800 typing-indicator">Aron is thinking</p>';
chatMessages.appendChild(typingIndicator);
chatMessages.scrollTop = chatMessages.scrollHeight;
// Simulate AI response after a delay
setTimeout(() => {
chatMessages.removeChild(typingIndicator);
processUserMessage(message);
}, 1500);
}
function processUserMessage(message) {
const lowerMessage = message.toLowerCase();
let response = '';
if (lowerMessage.includes('hello') || lowerMessage.includes('hi')) {
response = userName ? `Hello ${userName}! How can I assist you today?` : 'Hello there! How can I assist you today?';
} else if (lowerMessage.includes('your name') || lowerMessage.includes('who are you')) {
response = 'I am Aron, your personal voice assistant for task management and reminders.';
} else if (lowerMessage.includes('task') && (lowerMessage.includes('add') || lowerMessage.includes('create'))) {
response = 'To add a new task, please fill out the task form on the left. You can specify the task name, time, date, and priority. Or you can tell me now and I\'ll add it for you.';
} else if (lowerMessage.includes('task') && lowerMessage.includes('list')) {
if (tasks.length === 0) {
response = 'You currently have no scheduled tasks. Would you like to add one?';
} else {
const taskCount = tasks.length;
const upcomingTasks = tasks.filter(t => !t.completed && new Date(`${t.date}T${t.time}`) > new Date()).length;
response = `You have ${taskCount} task${taskCount !== 1 ? 's' : ''} in total, with ${upcomingTasks} upcoming. Check the task list below for details. Would you like me to go through them with you?`;
}
} else if (lowerMessage.includes('time') || lowerMessage.includes('date')) {
const now = new Date();
response = `The current date and time is ${now.toLocaleString('en-US', {
weekday: 'long',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
})}. Is there anything time-sensitive you\'d like me to help with?`;
} else if (lowerMessage.includes('thank')) {
const thanksResponses = [
"You're welcome! Is there anything else I can help you with?",
"My pleasure! Let me know if you need anything else.",
"Happy to help! What else can I do for you today?"
];
response = thanksResponses[Math.floor(Math.random() * thanksResponses.length)];
} else if (lowerMessage.includes('help')) {
response = "I can help you with: \n- Adding and managing tasks \n- Setting reminders \n- Answering general questions \n- Providing the current time and date \nJust ask! What would you like help with today?";
} else if (lowerMessage.includes('how are you') || lowerMessage.includes('how\'s it going')) {
const moodResponses = [
"I'm just a program, but I'm functioning perfectly well! How about you?",
"I don't have feelings, but I'm ready to assist you! How can I help?",
"I'm always at your service! What can I do for you today?"
];
response = moodResponses[Math.floor(Math.random() * moodResponses.length)];
} else {
const fallbackResponses = [
"I'm your task management assistant. I can help you add tasks, set reminders, and answer general questions. What would you like me to do?",
"I'm not sure I understand. Could you rephrase that? I can help with tasks, reminders, and general questions.",
"Let me think... I believe I can help you better if you ask about tasks, reminders, or general assistance. What would you like to know?"
];
response = fallbackResponses[Math.floor(Math.random() * fallbackResponses.length)];
}
addChatMessage('assistant', response);
speak(response);
}
function addChatMessage(sender, message, isReminder = false) {
const messageDiv = document.createElement('div');
messageDiv.className = `message-enter ${sender === 'user' ? 'ml-auto bg-blue-600 text-white rounded-lg p-4 max-w-xs' :
isReminder ? 'task-reminder rounded-lg p-4 max-w-xs' : 'bg-blue-50 rounded-lg p-4 max-w-xs'}`;
messageDiv.innerHTML = `<p>${message}</p>`;
chatMessages.appendChild(messageDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
function clearChat() {
chatMessages.innerHTML = `
<div class="message-enter bg-blue-50 rounded-lg p-4 max-w-xs">
<p class="text-gray-800">Hello! I'm Aron, your AI task assistant. You can say "Hey Aron" to wake me up or ask about your tasks.</p>
</div>
`;
}
// Make these functions available globally for button clicks
window.completeTask = completeTask;
window.deleteTask = deleteTask;
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=meer012/aron" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |