-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
89 lines (86 loc) · 3.9 KB
/
main.js
File metadata and controls
89 lines (86 loc) · 3.9 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
let count = 0
function Animation_Control() {
// this function starts animation and inistilize the speech recognize function
if(count %2 != 0){
Speek("Rocket shutdown.")
document.getElementById("coilcontainer").style.animationName = "none";
stopRocket();
}
else{
Speek("Voice assistaint started.")
document.getElementById("coilcontainer").style.animationName = "reactor-anim";
startRecognization();
}
count += 1
}
function Speek(speechToSpeek) {
window.speechSynthesis.speak(new SpeechSynthesisUtterance(speechToSpeek));
}
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new window.SpeechRecognition();
function startRecognization() {
recognition.interimResults = true;
recognition.addEventListener('result', (e) => {
let text = Array.from(e.results).map(result => result[0]).map(result => result.transcript).join('');
document.getElementById("voice_text").innerHTML=text;
console.log(text);
if (e.results[0].isFinal) {
text = text.toLowerCase()
if (text.includes('rocket')) {
document.getElementById("text_box").innerHTML = text;
console.log(text);
switch (true) {
case text.indexOf('open') != -1:
if (text.includes("whatsapp")) {
Speek("opening whatsapp")
window.open("https://www.whatsapp.com/","_blank");
}
else if (text.includes('instagram') || text.includes('insta') || text.includes('reels')) {
Speek("Openig Instagram")
window.open("https://www.instagram.com/","_blank");
}
else if (text.includes('youtube') || text.includes('videos')) {
Speek("Opening Youtube")
window.open("https://youtube.com/","_blank");
}
else if(text.includes('twitter')||text.includes('tweet')){
Speek("Opening twitter")
window.open("https://twitter.com");
}
else if(text.includes('discord')||text.includes('Discord')){
Speek("Opening discord")
window.open("https://discord.com/channels/@me");
}
else{
Speek("These are the Results i found")
idx = text.indexOf('open')
tosearch = text.slice(idx+5)
window.open('https://www.google.com/search?q='+tosearch);
}
break;
case text.indexOf('search') != -1:
idx = text.indexOf('search')
tosearch = text.slice(idx+7)
Speek("searching "+tosearch)
window.open('https://www.google.com/search?q='+tosearch);
break
case text.indexOf('help') != -1 || text.indexOf('show commands'):
Speek("These are the commands");
document.getElementById("help").click();
break
default:
Speek('Command not found .. please follow these commands');
document.getElementById("help").click();
break
}
}
}
})
recognition.addEventListener('end', () => {
recognition.start();
})
recognition.start();
}
function stopRocket() {
recognition.stop();
}