summaryrefslogtreecommitdiff
path: root/src/www/js/wc.js
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2014-03-17 15:59:43 +0000
committerhallgren <hallgren@chalmers.se>2014-03-17 15:59:43 +0000
commit22b68ad30cf9e5bd8e5ede60ec6c04d1294d18a7 (patch)
tree45411b8e03a483e15ed2e2b08b8fc02c781fda5d /src/www/js/wc.js
parent825e0cf7cf32802862fd88e5dac0cd2f8084d08b (diff)
Wide coverage demo web app: add speech synthesis
Works in Safari and Chrome.
Diffstat (limited to 'src/www/js/wc.js')
-rw-r--r--src/www/js/wc.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/www/js/wc.js b/src/www/js/wc.js
index 0a91ecf7a..431296e24 100644
--- a/src/www/js/wc.js
+++ b/src/www/js/wc.js
@@ -38,6 +38,7 @@ wc.translate=function() {
if(e) e.innerHTML=r.prob+"<br>"+r.tree
wc.current=i
if(wc.p /*&& wc.r.length>1*/) show_picks()
+ if(f.speak.checked) wc.speak(r.text,f.to.value)
}
function trans(text,i) {
@@ -66,6 +67,15 @@ wc.translate=function() {
return false;
}
+wc.speak=function(text,lang) {
+ if(wc.speech) {
+ var u=new SpeechSynthesisUtterance(text)
+ u.lang=add_country(alangcode(lang))
+ speechSynthesis.cancel()
+ speechSynthesis.speak(u)
+ }
+}
+
wc.swap=function() {
var f=wc.f
f.input.value=f.output.value;
@@ -88,3 +98,11 @@ wc.try_google=function() {
w.focus()
}
*/
+
+function init_speech() {
+ wc.speech=window.speechSynthesis && window.speechSynthesis.getVoices().length>0
+ if(wc.speech) element("speak").style.display="inline"
+}
+
+init_speech()
+setTimeout(init_speech,500) // A hack for Chrome.