diff --git a/jquery-turtle.js b/jquery-turtle.js index 19ab9cb..9f4064d 100644 --- a/jquery-turtle.js +++ b/jquery-turtle.js @@ -6886,6 +6886,7 @@ var turtlefn = { var msg = new SpeechSynthesisUtterance(words); msg.addEventListener('end', complete); msg.addEventListener('error', complete); + msg.lang = 'en-GB'; speechSynthesis.speak(msg); pollTimer = setInterval(function() { // Chrome speech synthesis fails to deliver an 'end' event @@ -9702,44 +9703,6 @@ function prepareInput(name, callback, type) { return false; } } - if (type == 'voice') { - var SR = global.SpeechRecognition || global.webkitSpeechRecognition; - if ('function' == typeof(SR)) { - try { - recognition = new SR(); - recognition.continuous = false; - recognition.interimResults = true; - textbox.css({backgroundColor: 'lightyellow', - color: 'gray', - backgroundImage: "url(" + microphoneSvg + ")", - backgroundRepeat: 'no-repeat', - backgroundPosition: 'center'}); - recognition.onspeechstart = function() { - textbox.css({background: 'lightgreen'}); - }; - recognition.onend = function() { - textbox.css({color: '', backgroundColor: '', backgroundImage: '', - backgroundRepeat: '', backgroundPosition: ''}); - textbox.val(lastseen); - newval(); - }; - recognition.onresult = function(event) { - var text = event.results[0][0].transcript; - var confidence = event.results[0][0].confidence; - var shade = 128 - 128 * confidence; - if (event.results[0].isFinal) { - shade = 0; - lastseen = text; - } - textbox.css({color: componentColor('rgb', shade, shade, shade)}); - textbox.val(text); - }; - recognition.start(); - } catch (e) { - console.log(e); - } - } - } textbox.on('keypress keydown', key); textbox.on('change', newval); return { @@ -9755,6 +9718,44 @@ function prepareInput(name, callback, type) { marginwidth = textbox.outerWidth(true) - textbox.width(); textbox.width(desiredwidth - marginwidth); } + if (type == 'voice') { + var SR = global.SpeechRecognition || global.webkitSpeechRecognition; + if ('function' == typeof(SR)) { + try { + recognition = new SR(); + recognition.continuous = false; + recognition.interimResults = true; + textbox.css({backgroundColor: 'lightyellow', + color: 'gray', + backgroundImage: "url(" + microphoneSvg + ")", + backgroundRepeat: 'no-repeat', + backgroundPosition: 'center'}); + recognition.onspeechstart = function() { + textbox.css({background: 'lightgreen'}); + }; + recognition.onend = function() { + textbox.css({color: '', backgroundColor: '', backgroundImage: '', + backgroundRepeat: '', backgroundPosition: ''}); + textbox.val(lastseen); + newval(); + }; + recognition.onresult = function(event) { + var text = event.results[0][0].transcript; + var confidence = event.results[0][0].confidence; + var shade = 128 - 128 * confidence; + if (event.results[0].isFinal) { + shade = 0; + lastseen = text; + } + textbox.css({color: componentColor('rgb', shade, shade, shade)}); + textbox.val(text); + }; + recognition.start(); + } catch (e) { + console.log(e); + } + } + } // Focus, but don't cause autoscroll to occur due to focus. undoScrollAfter(function() { textbox.focus(); }); }