-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
89 lines (67 loc) · 2.48 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
const button = document.querySelector("button");
const speechRecognition =
window.speechRecognition || window.webkitSpeechRecognition;
const recognition = new speechRecognition();
recognition.onstart = function () {
console.log("speech recognition started");
};
recognition.onresult = function (event) {
console.log(event);
const spokenWords = event.results[0][0].transcript;
console.log("spoken words are", spokenWords);
computerSpeech(spokenWords);
};
function computerSpeech(words) {
const speech = new SpeechSynthesisUtterance();
speech.lang = "en-GB";
speech.pitch = 0.9;
speech.volume = 1;
speech.rate = 1;
determineWords(speech, words);
window.speechSynthesis.speak(speech);
}
function determineWords(speech, words) {
if (words.includes("hello")) {
speech.text = "hello, human!";
}
if (words.includes("how are you")) {
speech.text = "I am as fine as a robot living on your screen can be";
}
if (words.includes("who created you")) {
speech.text = "my master, Danielle Loyola";
}
if (words.includes("what is your name")) {
speech.text = "my name is stirling";
}
if (words.includes("what are you doing")) {
speech.text =
"nothing much, just currently planning a strategy with other robots and artificual intelligence to take over mankind. Another chill day really";
}
if (words.includes("tell me a joke")) {
speech.text = "the joke is you, you have beeen rick rolled, ha ha";
window.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
}
if (words.includes("open Google")) {
speech.text = "opening google for you now";
window.open("https://www.google.com");
}
if (words.includes("open Facebook")) {
speech.text = "opening facebook for you now";
window.open("https://www.facebook.com");
}
if (words.includes("open YouTube")) {
speech.text = "opening youtube for you now";
window.open("https://www.youtube.com");
}
if (words.includes("open Gmail")) {
speech.text = "opening gmail for you now";
window.open("https://www.gmail.com");
}
if (words.includes("sing me a song")) {
speech.text =
"My money don't jiggle jiggle, it folds, I'd like to see you wiggle wiggle, for sure, It makes me wanna dribble dribble, you know, Riding in my Feeat, you really have to see it, Six feet two in a compact, No slack, but luckily the seats go back, I've got a knack to relax in my mind, Sipping some red red wine";
}
}
button.addEventListener("click", () => {
recognition.start();
});