!7
p-exp { serveHttpIfMain(8123); }
html {
ret htitle("Speech Output Test")
+ p("Press F12 to open console")
+ "Text to say: " + htextinput("text", id := "thetext", onKeyUp := [[if (event.keyCode == 13) { say(document.getElementById("thetext").value); return false; }]])
+ hjavascript([[
function say(text) {
console.log("Saying: " + text);
var u = new SpeechSynthesisUtterance(text);
u.volume = 0.25; // quarter volume
u.onstart = function() { console.log("Utterance start"); };
u.onend = function() { console.log("Utterance end"); };
u.onboundary = function() { console.log("Utterance boundary"); };
u.onerror = function() { console.log("Utterance error"); };
window.speechSynthesis.speak(u);
}
console.log("Voices: " + window.speechSynthesis.getVoices().length);
var speaking = true;
function checkStatus() {
var s = window.speechSynthesis.speaking;
if (s != speaking)
if (s)
console.log("Speaking");
else
console.log("Not speaking");
speaking = s;
setTimeout(checkStatus, 200);
}
checkStatus();
]]);
}