-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (21 loc) · 685 Bytes
/
index.js
File metadata and controls
23 lines (21 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Setup voices
function populateVoiceList() {
window.speechSynthesis.getVoices().forEach(voice => {
let voiceOption = document.createElement('option');
voiceOption.textContent = `${voice.name} / ${voice.lang}`;
voiceOption.value = voice.voiceURI;
window.voicesList.appendChild(voiceOption);
});
}
voicesList.addEventListener('click', () => {
if (!voicesList.textContent) {
populateVoiceList();
}
});
// Speak it
play.addEventListener('click', event => {
const utter = new SpeechSynthesisUtterance(input.value);
utter.voice = window.speechSynthesis.getVoices()[voicesList.selectedIndex];
// more settigs could be added here
window.speechSynthesis.speak(utter);
});