Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 39 additions & 38 deletions jquery-turtle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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(); });
}
Expand Down