-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
92 lines (89 loc) · 3.03 KB
/
Copy pathscript.js
File metadata and controls
92 lines (89 loc) · 3.03 KB
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
let btn = document.querySelector("#btn")
let content = document.querySelector("#content")
let voice = document.querySelector("#voice")
function speak(text) {
let text_speak = new SpeechSynthesisUtterance(text)
text_speak.rate = 1
text_speak.pitch = 1
text_speak.volume = 1
text_speak.lang = "hi-GB"
window.speechSynthesis.speak(text_speak)
}
function wishMe() {
let day = new Date()
let hours = day.getHours()
if (hours >= 0 && hours < 12) {
speak("Good Morning Sir")
}
else if (hours >= 12 && hours < 16) {
speak("Good afternoon Sir")
} else {
speak("Good Evening Sir")
}
}
// window.addEventListener('load',()=>{
// wishMe()
// })
let speechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
let recognition = new speechRecognition()
recognition.onresult = (event) => {
let currentIndex = event.resultIndex
let transcript = event.results[currentIndex][0].transcript
content.innerText = transcript
takeCommand(transcript.toLowerCase())
}
btn.addEventListener("click", () => {
recognition.start()
voice.style.display = "block"
btn.style.display = "none"
})
function takeCommand(message) {
voice.style.display = "none"
btn.style.display = "flex"
if (message.includes("hello") || message.includes("hey")) {
speak("hello sir,what can i help you?")
}
else if (message.includes("who are you")) {
speak("i am virtual assistant ,created by Rohan Kushwaha")
}
else if (message.includes("who created you")) {
speak("i am virtual assistant ,created by Rohan Kushwaha")
}
else if (message.includes("open youtube")) {
speak("opening youtube...")
window.open("https://youtube.com/", "_blank")
}
else if (message.includes("open google")) {
speak("opening google...")
window.open("https://google.com/", "_blank")
}
else if (message.includes("open facebook")) {
speak("opening facebook...")
window.open("https://facebook.com/", "_blank")
}
else if (message.includes("open instagram")) {
speak("opening instagram...")
window.open("https://instagram.com/", "_blank")
}
else if (message.includes("open calculator")) {
speak("opening calculator..")
window.open("calculator://")
}
else if (message.includes("open whatsapp")) {
speak("opening whatsapp..")
window.open("whatsapp://")
}
else if (message.includes("time")) {
let time = new Date().toLocaleString(undefined, { hour: "numeric", minute: "numeric" })
speak(time)
}
else if (message.includes("date")) {
let date = new Date().toLocaleString(undefined, { day: "numeric", month: "short" })
speak(date)
}
else {
let finalText = "this is what i found on internet regarding" + message.replace("LinkLearn", "") || message.replace("LinkLearn", "")
speak(finalText)
window.open(`https://www.google.com/search?q=${message.replace("LinkLearn", "")}`, "_blank")
}
}