-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript .js
More file actions
85 lines (80 loc) · 2.78 KB
/
Copy pathscript .js
File metadata and controls
85 lines (80 loc) · 2.78 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
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;
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 speechRecorginition =
window.SpeechRecognition || window.webkitSpeechRecognition;
let recognition = new speechRecorginition();
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();
btn.style.display = "none";
voice.style.display = "block";
});
function takeCommand(message) {
btn.style.display = "flex";
voice.style.display = "none";
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 Drone a virtual assistant, created by adarsh singh rajput");
} else if (message.includes("how are you")) {
speak("i am fine what about you?");
} else if (message.includes("tell")) {
speak("jai shree ram");
} else if (message.includes("open youtube")) {
speak("opening youtube");
window.open("https://www.youtube.com/", "_blank");
} else if (message.includes("open google")) {
speak("opening google");
window.open("https://www.google.com/", "_blank");
} else if (message.includes("open instagram")) {
speak("opening instagram");
window.open("https://www.instagram.com/", "_blank");
} else if (message.includes("open linkdin")) {
speak("opening linkdin");
window.open("https://www.linkdin.com/", "_blank");
} else if (message.includes("open github")) {
speak("opening github");
window.open("https://www.github.com/", "_blank");
} else if (message.includes("open twitter")) {
speak("opening twitter");
window.open("https://www.twitter.com/", "_blank");
} else if (message.includes("open spotify")) {
speak("opening spotify");
window.open("https://www.spotify.com/", "_blank");
} else {
speak(
`this is waht i found on internet regarding${message.replace(
"Hatim",
""
)}`
);
window.open(`https://www.google.com/search?q=${message}`);
}
}