From 8ce2cd9d706932613e49cb98db0592d9bc46c950 Mon Sep 17 00:00:00 2001 From: DuyVu Date: Tue, 11 Jun 2024 20:41:36 +0700 Subject: [PATCH] day30 --- Day_30/index.html | 67 ++++++++++++++++++++++++++++++++++++++++++++ Day_30/js/day30.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++ index.html | 5 ++++ 3 files changed, 142 insertions(+) create mode 100644 Day_30/index.html create mode 100644 Day_30/js/day30.js diff --git a/Day_30/index.html b/Day_30/index.html new file mode 100644 index 0000000..c45d889 --- /dev/null +++ b/Day_30/index.html @@ -0,0 +1,67 @@ + + + + + + + Day 30 + + + +

Bạn muốn làm gì? Hãy nói gì đó...

+ +

+

+ + + diff --git a/Day_30/js/day30.js b/Day_30/js/day30.js new file mode 100644 index 0000000..056286e --- /dev/null +++ b/Day_30/js/day30.js @@ -0,0 +1,70 @@ +var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition; + +var speakerBtn = document.querySelector("button"); +var notification = document.querySelector(".notification"); +var result = document.querySelector(".result"); +var utilities = { + "google maps": "https://www.google.com/maps", + "bản đồ": "https://www.google.com/maps", + maps: "https://www.google.com/maps", + "google drive": "https://drive.google.com/drive/home", + google: "https://www.google.com/", + youtube: "https://www.youtube.com/", + facebook: "https://www.facebook.com/", + "chỉ đường tới": "https://www.google.com/maps/search/", + "chỉ đường": "https://www.google.com/maps/search/", + "đường tới": "https://www.google.com/maps/search/", + tới: "https://www.google.com/maps/search/", + "mở bài hát": "https://zingmp3.vn/tim-kiem/tat-ca?q=", + "nghe bài hát": "https://zingmp3.vn/tim-kiem/tat-ca?q=", + "bài hát": "https://zingmp3.vn/tim-kiem/tat-ca?q=", + "mở video": "https://www.youtube.com/results?search_query=", + "xem video": "https://www.youtube.com/results?search_query=", + video: "https://www.youtube.com/results?search_query=", +}; + +console.log(Object.keys(utilities)); +function handlerSpeakers() { + var recognition = new SpeechRecognition(); + recognition.lang = "vi-VN"; + recognition.interimResults = false; + recognition.maxAlternatives = 1; + recognition.start(); + result.classList.remove("action"); + notification.classList.remove("action-green"); + notification.classList.add("action-red"); + notification.textContent = "Hãy nói nội dung bạn muốn"; + //fnc onresult() + var queryStr = ""; + var checkResult; + recognition.onresult = function (e) { + var speechResult = e.results[0][0].transcript.toLowerCase(); + result.classList.add("action"); + result.textContent = `Đang thực hiện: ${speechResult}`; + + for (var key of Object.keys(utilities)) { + checkResult = String(speechResult).indexOf(key); + if (checkResult !== -1) { + queryStr = String(speechResult).slice(key.length); + setTimeout(function () { + result.textContent = `Đã thực hiện xong.`; + window.open(`${utilities[key]}${queryStr}`, "_blank"); + }, 1200); + break; + } + } + if (checkResult === -1) { + setTimeout(function () { + result.textContent = `Không thực hiện được yêu cầu`; + }, 500); + } + console.log(speechResult); + }; + recognition.onspeechend = function () { + notification.classList.replace("action-red", "action-green"); + notification.textContent = "Đã nói xong. Hy vọng kết quả như ý bạn"; + recognition.stop(); + }; +} + +speakerBtn.addEventListener("click", handlerSpeakers); diff --git a/index.html b/index.html index 34f6edf..2551c1f 100644 --- a/index.html +++ b/index.html @@ -152,6 +152,11 @@

Danh sách bài tập

>Day_29 +
  • + Day_30 +