@@ -197,7 +197,6 @@
['yue-Hant-HK', '粵語 (香港)']],
['日本語', ['ja-JP']],
['Lingua latīna', ['la']]];
-
for (var i = 0; i < langs.length; i++) {
select_language.options[i] = new Option(langs[i][0], i);
}
@@ -211,12 +210,20 @@
select_dialect.remove(i);
}
var list = langs[select_language.selectedIndex];
- for (var i = 1; i < list.length; i++) {
- select_dialect.options.add(new Option(list[i][1], list[i][0]));
+ for (var j = 1; j < list.length; j++) {
+ select_dialect.options.add(new Option(list[j][1], list[j][0]));
}
select_dialect.style.visibility = list[1].length == 1 ? 'hidden' : 'visible';
+ if(recognizing){
+ ignore_onend = true;
+ recognition.stop();
+ setTimeout(function(){
+ recognition.lang = select_dialect.value;
+ ignore_onend = false;
+ recognition.start();
+ },500);
+ }
}
-
var create_email = false;
var final_transcript = '';
var recognizing = false;
@@ -229,13 +236,11 @@
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
-
recognition.onstart = function() {
recognizing = true;
showInfo('info_speak_now');
start_img.src = 'mic-animate.gif';
};
-
recognition.onerror = function(event) {
if (event.error == 'no-speech') {
start_img.src = 'mic.gif';
@@ -256,7 +261,6 @@
ignore_onend = true;
}
};
-
recognition.onend = function() {
recognizing = false;
if (ignore_onend) {
@@ -279,41 +283,38 @@
createEmail();
}
};
-
recognition.onresult = function(event) {
var interim_transcript = '';
+ var new_final_transcript = '';
for (var i = event.resultIndex; i < event.results.length; ++i) {
if (event.results[i].isFinal) {
- final_transcript += event.results[i][0].transcript;
+ new_final_transcript += event.results[i][0].transcript;
} else {
interim_transcript += event.results[i][0].transcript;
}
}
- final_transcript = capitalize(final_transcript);
- final_span.innerHTML = linebreak(final_transcript);
+//console.log(new_final_transcript);
+final_transcript = capitalize(new_final_transcript);
+final_span.innerHTML = final_span.innerHTML + linebreak(final_transcript);
interim_span.innerHTML = linebreak(interim_transcript);
if (final_transcript || interim_transcript) {
showButtons('inline-block');
}
};
}
-
function upgrade() {
start_button.style.visibility = 'hidden';
showInfo('info_upgrade');
}
-
var two_line = /\n\n/g;
var one_line = /\n/g;
function linebreak(s) {
return s.replace(two_line, '
').replace(one_line, '
');
}
-
var first_char = /\S/;
function capitalize(s) {
return s.replace(first_char, function(m) { return m.toUpperCase(); });
}
-
function createEmail() {
var n = final_transcript.indexOf('\n');
if (n < 0 || n >= 80) {
@@ -323,7 +324,6 @@
var body = encodeURI(final_transcript.substring(n + 1));
window.location.href = 'mailto:?subject=' + subject + '&body=' + body;
}
-
function copyButton() {
if (recognizing) {
recognizing = false;
@@ -333,7 +333,6 @@
copy_info.style.display = 'inline-block';
showInfo('');
}
-
function emailButton() {
if (recognizing) {
create_email = true;
@@ -346,7 +345,6 @@
email_info.style.display = 'inline-block';
showInfo('');
}
-
function startButton(event) {
if (recognizing) {
recognition.stop();
@@ -356,14 +354,13 @@
recognition.lang = select_dialect.value;
recognition.start();
ignore_onend = false;
- final_span.innerHTML = '';
+ //final_span.innerHTML = '';
interim_span.innerHTML = '';
start_img.src = 'mic-slash.gif';
showInfo('info_allow');
showButtons('none');
start_timestamp = event.timeStamp;
}
-
function showInfo(s) {
if (s) {
for (var child = info.firstChild; child; child = child.nextSibling) {
@@ -376,7 +373,6 @@
info.style.visibility = 'hidden';
}
}
-
var current_style;
function showButtons(style) {
if (style == current_style) {
@@ -388,4 +384,4 @@
copy_info.style.display = 'none';
email_info.style.display = 'none';
}
-
\ No newline at end of file
+