forked from benetech/BeneSpeak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
43 lines (37 loc) · 1.47 KB
/
demo.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
function speak() {
document.getElementById('speechDisplay').innerHTML = document.getElementById('speechInput').value;
var data = BeneSpeak.generateSpeechData(document.getElementById('speechDisplay'));
chrome.tts.speak(data.utterance, {
rate : parseFloat(document.getElementById("speechRate").value),
voiceName : document.getElementById("voice").options[document.getElementById("voice").selectedIndex].value,
onEvent : function(event) { data.handleTtsEvent(event); }
});
}
function updateSpeechRateDisplay() {
document.getElementById("speechRateDisplay").innerText = document.getElementById("speechRate").value;
}
function buildVoiceMenu() {
var menu = document.getElementById("voice");
chrome.tts.getVoices(
function(voices) {
for (var i = 0; i < voices.length; i++) {
console.log(voices[i]);
if (voices[i].eventTypes.indexOf("word") > -1) {
var opt = document.createElement("option");
opt.value = voices[i].voiceName;
opt.innerText = voices[i].voiceName;
menu.appendChild(opt);
}
}
}
);
}
document.onreadystatechange = function () {
if (document.readyState == "complete") {
document.getElementById('speakButton').onclick = speak;
document.getElementById('stopButton').onclick = function() { BeneSpeak.stop(); };
document.getElementById('speechRate').onchange = function() { updateSpeechRateDisplay(); };
document.getElementById('speechRate').value = 1;
buildVoiceMenu();
}
}