-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
129 lines (125 loc) · 3.76 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text to Speech</title>
<style>
* {
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
box-sizing: border-box;
}
.word {
width: 100%;
height: 100%;
min-height: 100vh;
background: linear-gradient(45deg, #eb8585, #6495ED);
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
color: white;
}
.word h1 {
font-weight: 500;
font-size: 45px;
margin-top: -50px;
margin-bottom: 50px;
}
.word h1 span {
color: rgb(242, 75, 128);
}
textarea {
width: 500px;
height: 250px;
font-size: 15px;
color: rgb(0, 0, 0);
background: rgb(176, 196, 236);
border: 0;
outline: 0;
padding: 20px;
border-radius: 20px;
margin-bottom: 30px;
resize: both;
}
textarea::placeholder {
font-size: 16px;
color: black;
}
.wow {
display: flex;
width: 500px;
gap: 20px;
align-items: center;
}
button {
background: rgb(247, 137, 230);
color: #fff;
padding: 10px 30px;
border-radius: 25px;
outline: 0;
font-size: medium;
cursor: pointer;
display: flex;
align-items: center;
}
button img {
width: 16px;
margin-right: 10px;
}
select {
flex: 1;
background: rgb(176, 196, 236);
color: #000000;
border: 0;
outline: 0;
padding: 10px;
border-radius: 20px;
}
</style>
</head>
<body>
<div class="word">
<h1>Text-To-Speech <span>Converter</span></h1>
<textarea id="text" placeholder="Write your text..."></textarea>
<div class="wow">
<select id="voiceSelect"></select>
<button id="speakButton">
<img src="play.png" alt="Play Icon">Listen
</button>
</div>
</div>
<script>
let speech = new SpeechSynthesisUtterance();
let voices = [];
// Populate voice options
function populateVoices() {
voices = window.speechSynthesis.getVoices();
let voiceSelect = document.getElementById("voiceSelect");
voiceSelect.innerHTML = ''; // Clear existing options
voices.forEach((voice, index) => {
let option = document.createElement("option");
option.value = index;
option.textContent = `${voice.name} (${voice.lang})`;
voiceSelect.appendChild(option);
});
speech.voice = voices[0]; // Set default voice
}
window.speechSynthesis.onvoiceschanged = populateVoices;
document.getElementById("voiceSelect").addEventListener("change", () => {
speech.voice = voices[document.getElementById("voiceSelect").value];
});
document.getElementById("speakButton").addEventListener("click", () => {
let text = document.getElementById("text").value;
if (text.trim() !== '') {
speech.text = text;
window.speechSynthesis.speak(speech);
} else {
alert("Please enter some text.");
}
});
</script>
</body>
</html>