Skip to content

Commit

Permalink
Update ESP32_SpeechRecognition.html
Browse files Browse the repository at this point in the history
  • Loading branch information
fustyles authored Aug 6, 2019
1 parent 2d1a714 commit 44e6a6b
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions ESP32_SpeechRecognition.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!--
Author: https://www.facebook.com/francefu 2019-08-05 19:00
Author: https://www.facebook.com/francefu 2019-08-06 23:00
Page
https://fustyles.github.io/webduino/ESP32_SpeechRecognition.html?STAIP&en-US
-->
Expand Down Expand Up @@ -115,11 +114,10 @@
<option value="ja-JP">日本語</option>
<option value="hi-IN">हिन्दी</option>
<option value="th-TH">ภาษาไทย</option>
</select>
<br>Say "ok" or "okay" to execute command.<br>
</select><br>
<input type="checkbox" id="chk" name="chk" checked>Say "ok" or "okay" to execute command.<br>
<div id="showText"></div>
<div id="result" style="color:red;font-weight:bold;"></div>
<br>
<div id="result" style="color:red;font-weight:bold;"></div><br>
<div id="command" style="color:blue;font-weight:bold;"></div>

<script>
Expand All @@ -129,8 +127,9 @@
var one_line = /\n/g;
var first_char = /\S/;

var myString = "";
var myTimer;
var errTemp = "";
var errTimer;
var chkTimer;

if ('webkitSpeechRecognition' in window) {
var recognition = new webkitSpeechRecognition();
Expand Down Expand Up @@ -187,7 +186,7 @@
if (Recognition_interim=='') {
Recognition_final = linebreak(final_transcript);
console.log("result= " + Recognition_final);

if (Recognition_final.toLowerCase().trim()=="ok"||Recognition_final.toLowerCase().trim()=="okay") {
document.getElementById("showText").innerHTML = "";
document.getElementById("result").innerHTML = "";
Expand All @@ -198,27 +197,39 @@
document.getElementById("showText").innerHTML = "";
document.getElementById("result").innerHTML = Recognition_final;
document.getElementById("command").innerHTML = "http://" +STAIP + "?speech=" + Recognition_final.toLowerCase().trim() + ";" + document.getElementById("lang").value;
if (document.getElementById("chk").checked == false) {
document.getElementById("showText").innerHTML = "";
document.getElementById("result").innerHTML = "";
location.href = document.getElementById("command").innerHTML;
return;
}
}
}
else {
Recognition_final = "";
document.getElementById("showText").innerHTML = Recognition_interim;
console.log(Recognition_interim);

clearTimeout(myTimer);
myString = Recognition_interim;
myTimer = setTimeout(function() {
if (myString==document.getElementById("showText").innerHTML&&myString!="") {
if (myString.toLowerCase().trim()=="ok"||myString.toLowerCase().trim()=="okay") {
clearTimeout(errTimer);
errTemp = Recognition_interim;
errTimer = setTimeout(function() {
if (errTemp==document.getElementById("showText").innerHTML&&errTemp!="") {
if (errTemp.toLowerCase().trim()=="ok"||errTemp.toLowerCase().trim()=="okay") {
document.getElementById("showText").innerHTML = "";
document.getElementById("result").innerHTML = "";
location.href = document.getElementById("command").innerHTML;
return;
}
else {
document.getElementById("showText").innerHTML = "";
document.getElementById("result").innerHTML = myString;
document.getElementById("command").innerHTML = "http://" +STAIP + "?speech=" + myString.toLowerCase().trim() + ";" + document.getElementById("lang").value;
document.getElementById("result").innerHTML = errTemp;
document.getElementById("command").innerHTML = "http://" +STAIP + "?speech=" + errTemp.toLowerCase().trim() + ";" + document.getElementById("lang").value;
if (document.getElementById("chk").checked == false) {
document.getElementById("showText").innerHTML = "";
document.getElementById("result").innerHTML = "";
location.href = document.getElementById("command").innerHTML;
return;
}
}
}
}, 3000);
Expand Down

0 comments on commit 44e6a6b

Please sign in to comment.