-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
387 lines (334 loc) · 10.6 KB
/
app.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
// file
const startBtn = document.querySelector('#start');
const stopBtn = document.querySelector('#end');
const speakBtn = document.querySelector('#speak');
const time = document.querySelector('#time');
const battery = document.querySelector('#battery')
const internet = document.querySelector('#internet')
const turn_on = document.querySelector('#turn_on')
const msgs = document.querySelector(".messages")
document.querySelector("#start_rolex_btn").addEventListener("click", () =>{
recognition.start()
})
// rolex's commands
let rolexComs = [];
rolexComs.push("hi rolex");
rolexComs.push("what are your commands");
rolexComs.push("close this - to close opened popups");
rolexComs.push(
"change my information - information regarding your acoounts and you"
);
// rolexComs.push("whats the weather or temperature");
// rolexComs.push("show the full weather report");
rolexComs.push("are you there - to check rolexs presence");
rolexComs.push("shut down - stop voice recognition");
rolexComs.push("open google");
rolexComs.push('search for "your keywords" - to search on google ');
rolexComs.push("open whatsapp");
rolexComs.push("open youtube");
rolexComs.push('play "your keywords" - to search on youtube ');
rolexComs.push("close this youtube tab - to close opened youtube tab");
rolexComs.push("open firebase");
rolexComs.push("open netlify");
rolexComs.push("open twitter");
rolexComs.push("open my twitter profile");
// rolexComs.push("open instagram");
rolexComs.push("open my linkedin profile");
rolexComs.push("open github");
rolexComs.push("open my coding profile");
rolexComs.push("Find my deivice")
rolexComs.push("loacte")
//speech recogition setup
const SpeechRecognition =
window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
// sr start
recognition.onstart = function(){
console.log("vr active");
};
// create a new chat
function createMsg(who,msg){
let newmsg = document.createElement('p')
newmsg.innerText = msg;
newmsg.setAttribute('class',who)
msgs.appendChild(newmsg)
}
// time setup
let date = new Date()
let hrs = date.getHours()
let mins = date.getMinutes()
let secs = date.getSeconds()
// autojarvis
function autojarvis(){
setTimeout(()=>{
recognition.start()
},1000)
}
// onload window
window.onload = () =>{
// onstartup
turn_on.play()
turn_on.addEventListener('onend' , ()=>{
setTimeout(()=> {
autojarvis()
readOut('Ready To Go Sir')
if(localStorage.getItem('rolex_setup')=== null){
readOut('Please fill out the form')
}
},200);
})
// rolex commands adding
rolexComs.forEach((e) =>{
document.querySelector('.commands').innerHTML += `<p>#${e}</p><br/>`
})
// time setup
time.textContent = `${hrs}:${mins}:${secs}`
time.style.color = 'white'
setInterval(() => {
let date = new Date()
let hrs = date.getHours()
let mins = date.getMinutes()
let secs = date.getSeconds()
time.textContent = `${hrs}:${mins}:${secs}`
},1000);
// battery setup
let batteryPromise = navigator.getBattery()
batteryPromise.then(batteryCallback)
function batteryCallback(batteryObject){
printBatteryStatus(batteryObject)
setInterval(()=>{
printBatteryStatus(batteryObject)
},5000);
}
battery.style.color = 'white'
function printBatteryStatus(batteryObject){
battery.textContent = `${batteryObject.level*100}%`
if (batteryObject.charging = true){
document.querySelector('.battery').style.width = '10px'
battery.textContent = `${batteryObject.level*100}% Charge`
}
else if (batteryObject.charging = false){battery.textContent = `${batteryObject.level*100}%`}
}
// internet connectivity
if(navigator.onLine){
document.querySelector("#internet").textContent = "online"
connectivity = "online"
} else {
document.querySelector("#internet").textContent = "offline"
connectivity = "offline"
}
internet.style.color = 'white'
setInterval(() => {
if(navigator.onLine){
document.querySelector("#internet").textContent = "online"
connectivity = "online"
} else {
document.querySelector("#internet").textContent = "offline"
connectivity = "offline"
}
}, 6000);
}
// power up rolex
let play = document.getElementById("heart");
function playMusic() {
let audio = new Audio("assets/audio/Jarvis.mp3");
audio.play()
}
play.addEventListener("click", playMusic);
//result
recognition.onresult = function(event){
let current = event.resultIndex;
let transcript = event.results[current][0].transcript;
let userdata = localStorage.getItem('rolex_setup')
createMsg("usermsg",transcript)
console.log(event);
transcript = transcript.toLowerCase();
if(transcript.includes("hello rolex")){
readOut("hello sir");
}
if(transcript.includes("close this")){
readOut("closed")
document.querySelector('.commands').style.display = 'none';
setup.style.display = 'none'
}
if(transcript.includes("commands")){
readOut("Sir, I follow the following commands ");
document.querySelector('.commands').style.display = 'block';
}
if (transcript.includes("open youtube")){
readOut("opening youtube sir!");
window.open("https://www.youtube.com/")
}
if (transcript.includes("open google")){
readOut("opening google sir!");
window.open("https://www.google.com/");
}
if(transcript.includes('motivational')){
readOut("you only fail, when you stop trying!")
return;
}
if(transcript.includes('drive')){
readOut("opening your drive sir!")
window.open("https://drive.google.com/drive/my-drive");
return;
}
if(transcript.includes('mails')){
readOut("checking your mails sir!")
window.open("https://mail.google.com/mail/u/0/#inbox");
return;
}
if(transcript.includes('amazon')){
readOut("opening amazon shopping sir!")
window.open("https://www.amazon.in/");
return;
}
if(transcript.includes('find my device') ){
readOut("locating your device sir!")
window.open("https://www.google.com/android/find/");
return;
}
if(transcript.includes('weather today') || (transcript.includes('todays weather report'))){
readOut("here is the report")
window.open("https://www.accuweather.com/en/in/bengaluru/204108/weather-forecast/204108");
return;
}
if(transcript.includes('stocks today') || (transcript.includes('stocks to buy today'))){
readOut("here are some suggestions!")
window.open("https://in.investing.com/equities/most-active-stocks");
return;
}
if (transcript.includes('open whatsapp')) {
readOut('Opening whats app Sir')
window.open('https://web.whatsapp.com/')
return;
}
//google search
if (transcript.includes("search for")) {
let input = transcript.split("search for").at(-1)
console.log(input);
readOut(`searching for ${input}`)
window.open(`https://www.google.com/search?q=${input}`)
return;
}
if (transcript.includes('play the song')) {
let input = transcript.split("play the song").at(-1)
readOut(`playing ${input} from spotify`)
input = input.replace(' ', '%20')
console.log(input)
window.open(`https://open.spotify.com/search/${input}`)
return;
}
// youtube search
if (transcript.includes("play")) {
let input = transcript.split("play").at(-1)
console.log(input);
readOut(`playing ${input} from youtube! sir..`)
window.open(`https://www.youtube.com/results?search_query=${input}`);
return;
}
// Maps
// locate kormangala
if (transcript.includes('locate')) {
let input = transcript.split("locate").at(-1)
readOut(`locating ${input} from google maps`)
input = input.replace(' ', '+')
console.log(input)
window.open(`https://www.google.com/maps/search/${input}/`)
return;
}
if (transcript.includes("open my github profile") || transcript.includes('open my coding profile')) {
readOut('Opening your github profile sir')
window.open(`https://github.com/${JSON.parse(userdata).github}`)
return;
}
if (transcript.includes("open my linkedin profile")) {
readOut('Opening your linkedin profile sir')
window.open(`https://www.linkedin.com/${JSON.parse(userdata).linkedin}`)
return;
}
if (transcript.includes("owner")){
readOut(`Currently my owner is ${JSON.parse(userdata).name}`)
return;
}
if (transcript.includes('founder')){
readOut('I was created by my god kupendra sir')
}
if (transcript.includes("open github")) {
readOut('Opening github sir')
window.open('https://github.com/')
return;
}
if(transcript.includes('twitter profile') ){
readOut("opening your twitter profile sir!")
window.open("https://twitter.com/kupendrav99");
return;
}
if(transcript.includes('linkedin profile') ){
readOut("opening your linkedin profile sir!")
window.open("https://www.linkedin.com/in/kupendra-v2903/");
return;
}
// if (transcript) {
// readOut("i didn't get your sir")
// }
};
if (localStorage.getItem("rolex_setup") !== null){
}
// rolex setup
const setup = document.querySelector(".rolex_setup")
// setup.style.display = "none"
if(localStorage.getItem('rolex_setup') === null){
// setup.style.display = 'block'
setup.querySelector('button').addEventListener('click',userInfo)
}
// userinfo setup
function userInfo(){
let setupInfo = {
name: setup.querySelectorAll('input')[0].value,
bio : setup.querySelectorAll('input')[1].value,
github : setup.querySelectorAll('input')[2].value,
twitter : setup.querySelectorAll('input')[3].value,
linkedIn : setup.querySelectorAll('input')[4].value,
}
let testArr = []
setup.querySelectorAll('input').forEach((e) =>{
testArr.push(e.value)
})
if(testArr.includes('')){
readOut('⚠️Please Enter your complete information')
} else{
localStorage.clear()
localStorage.setItem(
'rolex_setup', JSON.stringify({...setupInfo})
)
setup.style.display = "none"
}
}
// end
recognition.onend = function (){
console.log("vr deactive");
};
//sr continuos
recognition.continuous = true ;
startBtn.addEventListener('click', () => {
recognition.start();
});
stopBtn.addEventListener('click', () => {
recognition.stop();
});
function readOut(message){
const speech = new SpeechSynthesisUtterance();
// diff voice
const allVoices = speechSynthesis.getVoices(2)
speech.text = message;
// speech.text = ' helo';
speech.voice = allVoices[0]
speech.volume = 122;
// window.speechSynthesis.speak(speech)
window.speechSynthesis.speak(speech);
console.log("speaking out");
createMsg('jmsg',message)
}
speakBtn.addEventListener("click",() => {
readOut("good afternoon sir!");
});