Загрузка данных
const status = document.getElementById('status');
const transcriptDiv = document.getElementById('transcript');
const circle = document.getElementById('circle');
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.lang = 'ru-RU';
// ! слушает тебя вечно
recognition.continuous = true;
// ! получает результат в режиме реального времени
recognition.interimResults = true;
// ! пока мы ничего не выполняем когда запускаем программу
let isStarted = false;
// Функция синтеза речи
// ! функция speak("погода")
// * бот будет отвечать, и я его буду слышать
function speak(message) {
const utterance = new SpeechSynthesisUtterance(message);
utterance.lang = 'ru-RU';
utterance.rate = 1.0;
window.speechSynthesis.speak(utterance);
}
// Запуск распознавания
function startJarvis() {
if (!isStarted) {
recognition.start();
isStarted = true; // * if True
status.innerText = "Джарвис на связи";
document.querySelector('.btn-start').innerText = "Перезапустить";
speak("Системы активны. Слушаю вас, сэр.");
}
}
recognition.onstart = () => {
circle.classList.add('active');
console.log("Распознавание запущено...");
};
recognition.onend = () => {
if (isStarted) recognition.start(); // Авто-перезапуск
};
recognition.onresult = (event) => {
let interimTranscript = ''; //! что ты сказал
let finalTranscript = ''; //! как он это понял
for (let i = event.resultIndex; i < event.results.length; ++i) {
if (event.results[i].isFinal) {
finalTranscript += event.results[i][0].transcript;
} else {
interimTranscript += event.results[i][0].transcript;
}
}
transcriptDiv.innerText = interimTranscript || finalTranscript;
if (finalTranscript) { //! Telegram открой -> telegram открой -> telegram
const command = finalTranscript.toLowerCase().trim();
console.log("Распознано:", command);
// --- ЛОГИКА КОМАНД ---
// 1. YouTube
if (command.includes('ютуб')) {
speak("Открываю Ютуб");
window.open('https://youtube.com', '_blank');
}
// 2. Pinterest
else if (command.includes('pinterest') || command.includes('картинки')) {
speak("Секунду, открываю Пинтерест");
window.open('https://pinterest.com', '_blank');
}
// 3. Telegram
else if (command.includes('telegram') || command.includes('телега')) {
speak("Открываю Телеграм");
window.open('https://web.telegram.org', '_blank');
}
// 4. Discord
else if (command.includes('discord') || command.includes('диск')) {
speak("Захожу в Дискорд");
window.open('https://discord.com/app', '_blank');
}
// 5. Проводник (Заглушка через Google Drive)
else if (command.includes('проводник') || command.includes('мои файлы')) {
speak("Проводник недоступен, открываю ваше облачное хранилище");
window.open('https://drive.google.com', '_blank');
}
// 6. Динамический поиск (Команда "Найди [что-то]")
else if (command.includes('найди')) {
const query = command.replace('найди', '').trim();
speak("Ищу информацию по запросу " + query);
window.open(`https://www.google.com/search?q=${query}`, '_blank');
}
// 7. Погода (Пример полезной команды)
else if (command.includes('погода')) {
speak("Открываю прогноз погоды");
window.open('https://yandex.ru/pogoda/ru/moscow', '_blank');
}
// 8. Закрытие (Визуальное)
else if (command.includes('отбой') || command.includes('спать')) {
speak("Ухожу в режим ожидания");
transcriptDiv.innerText = "Сплю...";
circle.classList.remove('active');
}
}
};
// Обработка ошибок
recognition.onerror = (event) => {
console.error("Ошибка распознавания:", event.error);
if (event.error === 'not-allowed') {
status.innerText = "Ошибка: Доступ к микрофону закрыт";
}
};