// requires JQuery sS hSpeechRecognition(O jsOnSpeech, S divName) { S language = "de-DE"; ret hjavascript([[ var bigOn = #BIGON#, pause = false, listening = false; function update() { if (bigOn) { if ($("#speechOnBtn")) $("#speechOnBtn").html("Turn off"); } else { if ($("#speechOnBtn")) $("#speechOnBtn").html("Turn on"); } var should = bigOn && !pause; if (should && !listening) startRecognition(); else if (!should && listening) stopRecognition(); } function stopRecognition() { listening = false; recognition.stop(); update(); } function startRecognition() { listening = true; recognition.start(); update(); } var recognition = new webkitSpeechRecognition(); recognition.lang = "#LANGUAGE#"; recognition.onerror = function(event) { var s = " "; if (event.error != "no-speech") s = "Error: " + event.error; $("#results").html(s); //stopRecognition(); // do we get onEnd later? //setTimeout(startRecognition, 1000); // safety delay } recognition.onresult = function(event) { var result = event.results[0]; var transcript = result[0].transcript; $("#results").html("Transcript: " + transcript); websocket.send(transcript); } recognition.onnomatch = function(event) { $("#results").html("-"); } recognition.onend = function(event) { listening = false; setTimeout(update, 100); } function startOrStop() { bigOn = !bigOn; update(); } ]] .replace("#BIGON#", str(autoTurnOn)) .replace("#LANGUAGE#", language)); }