-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
131 lines (124 loc) · 2.62 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
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
// Code for random french word Generator
// word Dict with {fr:en} words
const wordDict = {
partie: "part",
histoire: "history",
chercher: "search",
seulement: "only",
police: "police",
pensais: "thought",
aide: "help",
demande: "request",
genre: "kind",
mois: "month",
frère: "brother",
laisser: "to leave",
car: "because",
mettre: "to put",
aucun: "no",
laisse: "leash",
eux: "them",
ville: "city",
chaque: "each",
parler: "to speak",
faire: "to do",
arriver: "to come",
devrait: "should",
bébé: "baby",
longtemps: "long time",
heures: "hours",
découvrir: "to discover",
monde: "world",
pendant: "while",
revoir: "meet again",
aucune: "any",
place: "square",
comprendre: "to understand",
savoir: "to know",
être: "to be",
attention: "Warning",
voici: "here is",
pouvoir: "to be able to",
donner: "to give",
leurs: "their",
train: "train",
corps: "body",
endroit: "place",
yeux: "eyes",
façon: "way",
écouter: "to listen",
dont: "whose",
trouver: "to find",
premier: "first",
perdre: "to lose",
main: "hand",
première: "first",
côté: "side",
vieux: "old",
sois: "be",
tiens: "here",
matin: "morning",
tellement: "so much",
enfant: "child",
point: "point",
ensuite: "after",
pardon: "sorry",
venir: "to come",
devant: "in front of",
vers: "towards",
minutes: "minutes",
demandé: "request",
chambre: "bedroom",
mis: "placed",
belle: "beautiful",
droit: "law",
aimer: "to like",
"aujourd'hui": "today",
mari: "husband",
cause: "cause",
enfin: "finally",
espère: "hope",
eau: "water",
attendre: "to wait",
partir: "to leave",
nouvelle: "new",
travaill: "job",
arrêter: "to stop",
dire: "to say",
terre: "Earth",
compte: "account",
loin: "far",
fin: "end",
croire: "to believe",
chérie: "sweetheart",
gros: "large",
plutôt: "rather",
avoir: "to have",
filles: "girls",
jouer: "to play",
bureau: "office",
};
// get random key from wordDict
const randomKey = (obj) => {
var keys = Object.keys(obj);
return keys[(keys.length * Math.random()) << 0];
};
// generate random word
function getRandomWord() {
const randFrWord = randomKey(wordDict);
const randEnWord = wordDict[randFrWord];
document.getElementById("rand-fr-word").innerHTML = randFrWord;
document.getElementById("rand-en-word").innerHTML = randEnWord;
}
// Speech synthesis code
function speak(msg, isFrench) {
// creat SpeechSynthesisUtterance instance
let speech = new SpeechSynthesisUtterance();
// ternary operator for changing speech language
speech.lang = isFrench ? "fr" : "en";
speech.text = msg;
speech.volume = 1;
speech.rate = 1;
speech.pitch = 1;
window.speechSynthesis.speak(speech);
};