-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathword.html
More file actions
80 lines (73 loc) · 2.04 KB
/
word.html
File metadata and controls
80 lines (73 loc) · 2.04 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
<!DOCTYPE html>
<html>
<head>
<title>Word Generator with TTS</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
text-align: center;
padding: 50px;
}
.word-box {
font-size: 2em;
color: #333;
margin-top: 20px;
border: 2px solid #333;
display: inline-block;
padding: 10px;
margin-right: 10px;
}
button {
margin-top: 20px;
padding: 10px 20px;
font-size: 1em;
cursor: pointer;
}
#wordContainer {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Word Generator with TTS</h1>
<input type="number" id="numWords" min="1" max="10" value="1">
<button onclick="generateWords()">Generate Words</button>
<div id="wordContainer"></div>
<script>
function generateWord() {
const vowels = 'aeiou';
const consonants = 'bcdfghjklmnpqrstvwxyz';
let word = '';
let wordLength = Math.floor(Math.random() * 5) + 3; // Words between 3 and 7 letters
for (let i = 0; i < wordLength; i++) {
if (i % 2 === 0) {
word += consonants.charAt(Math.floor(Math.random() * consonants.length));
} else {
word += vowels.charAt(Math.floor(Math.random() * vowels.length));
}
}
return word;
}
function generateWords() {
let numWords = document.getElementById('numWords').value;
let wordContainer = document.getElementById('wordContainer');
wordContainer.innerHTML = '';
for (let i = 0; i < numWords; i++) {
let wordDiv = document.createElement('div');
wordDiv.className = 'word-box';
let word = generateWord();
wordDiv.innerText = word;
let ttsButton = document.createElement('button');
ttsButton.innerText = '🔊';
ttsButton.onclick = function() {
let utterance = new SpeechSynthesisUtterance(word);
speechSynthesis.speak(utterance);
};
wordDiv.appendChild(ttsButton);
wordContainer.appendChild(wordDiv);
}
}
</script>
</body>
</html>