Spaces:
Running
Running
Update index.html
Browse files- index.html +60 -18
index.html
CHANGED
@@ -1,19 +1,61 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Text to Speech</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
text-align: center;
|
11 |
+
padding: 20px;
|
12 |
+
}
|
13 |
+
textarea {
|
14 |
+
width: 80%;
|
15 |
+
height: 100px;
|
16 |
+
margin-bottom: 10px;
|
17 |
+
}
|
18 |
+
select, button {
|
19 |
+
margin: 10px;
|
20 |
+
padding: 10px;
|
21 |
+
}
|
22 |
+
</style>
|
23 |
+
</head>
|
24 |
+
<body>
|
25 |
+
<h1>Text to Speech</h1>
|
26 |
+
<textarea id="text" placeholder="Enter text to speak..."></textarea>
|
27 |
+
<br>
|
28 |
+
<select id="voiceSelect"></select>
|
29 |
+
<br>
|
30 |
+
<button onclick="speak()">Speak</button>
|
31 |
+
|
32 |
+
<script>
|
33 |
+
const synth = window.speechSynthesis;
|
34 |
+
const voiceSelect = document.getElementById('voiceSelect');
|
35 |
+
|
36 |
+
function loadVoices() {
|
37 |
+
const voices = synth.getVoices();
|
38 |
+
voiceSelect.innerHTML = '';
|
39 |
+
voices.forEach(voice => {
|
40 |
+
const option = document.createElement('option');
|
41 |
+
option.value = voice.name;
|
42 |
+
option.textContent = `${voice.name} (${voice.lang})`;
|
43 |
+
voiceSelect.appendChild(option);
|
44 |
+
});
|
45 |
+
}
|
46 |
+
|
47 |
+
function speak() {
|
48 |
+
const text = document.getElementById('text').value;
|
49 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
50 |
+
const selectedVoice = voiceSelect.value;
|
51 |
+
utterance.voice = synth.getVoices().find(voice => voice.name === selectedVoice);
|
52 |
+
synth.speak(utterance);
|
53 |
+
}
|
54 |
+
|
55 |
+
loadVoices();
|
56 |
+
if (speechSynthesis.onvoiceschanged !== undefined) {
|
57 |
+
speechSynthesis.onvoiceschanged = loadVoices;
|
58 |
+
}
|
59 |
+
</script>
|
60 |
+
</body>
|
61 |
</html>
|