-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttv.js
48 lines (42 loc) · 1.19 KB
/
ttv.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
45
46
47
48
var convert = document.getElementById('convert'),
voiceIco = document.getElementById('voiceIco'),
speech = document.getElementById('inputText'),
count = 1;
speech.addEventListener('change',function(){
speechText = this.value;
speechSynthesis.cancel();
convert.innerHTML = "Text to Speech";
voiceIco.innerHTML="🔈";
});
convert.addEventListener('click',function(){
if(!speechSynthesis.speaking || speechSynthesis.pause()){
speechText = speech.value;
var speechVoice = new SpeechSynthesisUtterance();
var voices = speechSynthesis.getVoices();
speechVoice.voice = voices[2];
speechVoice.text = speechText;
speechVoice.lang = 'en-US';
speechSynthesis.speak(speechVoice);
}
if(count == 1){
convert.innerHTML = "Play";
voiceIco.innerHTML="🔊";
speechSynthesis.resume()
setTimeout(() => {
count = 2;
}, 300);
}else{
speechSynthesis.paused
convert.innerHTML = "Pause";
voiceIco.innerHTML="🔈";
count = 1;
}
setInterval(() => {
if(!speechSynthesis.speaking && count == 2){
convert.innerHTML = "Text to Speech";
voiceIco.innerHTML="🔈";
count = 1;
console.log(count)
}
},100);
})