-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText-to-Speech
More file actions
26 lines (24 loc) · 766 Bytes
/
Copy pathText-to-Speech
File metadata and controls
26 lines (24 loc) · 766 Bytes
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
<!DOCTYPE html>
<html>
<head>
<title>Text-to-Speech Example</title>
</head>
<body>
<h1>Text-to-Speech Example</h1>
<textarea id="textInput" rows="4" cols="50" placeholder="Type something..."></textarea>
<br>
<button id="speakButton">Speak</button>
<script>
const textInput = document.getElementById('textInput');
const speakButton = document.getElementById('speakButton');
const synth = window.speechSynthesis;
speakButton.addEventListener('click', () => {
const text = textInput.value;
if (text !== '') {
const utterance = new SpeechSynthesisUtterance(text);
synth.speak(utterance);
}
});
</script>
</body>
</html>