-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
88 lines (85 loc) · 2.87 KB
/
script.js
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
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 adarsh sir")
}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("shipra","") || message.replace("shifra","")
speak(finalText)
window.open(`https://www.google.com/search?q=${message.replace("shipra","")}`,"_blank")
}
}