-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
22 lines (22 loc) · 756 Bytes
/
Copy pathscript.js
File metadata and controls
22 lines (22 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const input_btn = document.querySelector("#input-btn");
const options = document.querySelector("#voice")
let voices = speechSynthesis.getVoices();
if (voices) {
for (i = 0; i < voices.length; i++) {
options.innerHTML += `<option value="${voices[i].name}">${voices[i].name}</option>`
// console.log(voices[i].name)
}
}else{
options.style.display = 'none';
}
input_btn.addEventListener('click', () =>{
const text = document.querySelector("#input-text").value;
if(text){
let utterance = new SpeechSynthesisUtterance(text);
let value = options.value;
voices.forEach(voice => {
if(value === voice.name) utterance.voice = voice
});
speechSynthesis.speak(utterance);
}
})