-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
44 lines (35 loc) · 1.04 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
("use strict");
// Selecting Elements
const text = document.getElementById("txt");
const submitBtn = document.getElementById("submit");
const resumeBtn = document.getElementById("resume");
const pauseBtn = document.getElementById("pause");
let audioMessage;
submitBtn.addEventListener("click", () => {
// Set The Text
audioMessage.text = text.value;
// Speak The Text
window.speechSynthesis.speak(audioMessage);
});
resumeBtn.addEventListener("click", () => {
pauseBtn.style.display = "block";
resumeBtn.style.display = "none";
// Resume The Audio if It is paused
if (speechSynthesis.pause) {
speechSynthesis.resume();
}
});
pauseBtn.addEventListener("click", () => {
pauseBtn.style.display = "none";
resumeBtn.style.display = "block";
// Pause if speaking
speechSynthesis.speaking ? speechSynthesis.pause() : "";
});
window.onload = () => {
resumeBtn.style.display = "none";
if ("speechSynthesis" in window) {
audioMessage = new SpeechSynthesisUtterance();
} else {
alert("Speech Synthese is not supported");
}
};