diff --git a/demo/index.php b/demo/index.php
index 633fbf3..925b467 100644
--- a/demo/index.php
+++ b/demo/index.php
@@ -50,7 +50,7 @@
const resultHandler = markWord;
const resetHandler = resetColors;
-
+
diff --git a/demo/resultHandle_demo.js b/demo/resultHandle_demo.js
new file mode 100644
index 0000000..d14e06c
--- /dev/null
+++ b/demo/resultHandle_demo.js
@@ -0,0 +1,29 @@
+function handleResult(res, handleIt, reset=null) {
+ if (typeof reset == "function") {
+ reset();
+ }
+ var wordHandled = false;
+ words = res.result;
+ words.forEach((x) => {
+ if (allWords.includes(x.word)) {
+ wordHandled = true;
+ handleIt(x.word, x.conf);
+ }
+ });
+ if (!wordHandled) {
+ console.log("Got undefined word: " + res.text);
+ if (allWords.includes("")) {
+ handleIt('', 1);
+ }
+ }
+}
+
+function sendCommand(w, c) {
+ if (c >= .5) {
+ const action = eventWordMap[w];
+ console.log(`${w} detected with confidence ${c}: action ${action}`);
+ for (const callback of callbacks) {
+ callback(action);
+ }
+ }
+}
diff --git a/script/resultHandling.js b/script/resultHandling.js
index 4693e46..c9a6a8b 100644
--- a/script/resultHandling.js
+++ b/script/resultHandling.js
@@ -1,5 +1,5 @@
-// allWords = ['volgende', 'vorige']
+const allWords = ['volgende', 'vorige']
const callbacks = [];
const eventWordMap = {
'vorige': 'navigate-backward',
@@ -29,12 +29,6 @@ function handleResult(res, handleIt, reset=null) {
handleIt(x.word, x.conf);
}
});
- if (!wordHandled) {
- // console.log("Got undefined word: " + res.text);
- if (allWords.includes("")) {
- handleIt('', 1);
- }
- }
}
function sendCommand(w, c) {
@@ -45,4 +39,12 @@ function sendCommand(w, c) {
callback(action);
}
}
-}
\ No newline at end of file
+}
+
+thisRec = new VoskJS.Recognizer("model-nl.tar.gz")
+thisRec.onresult = result => {
+ if (result.result) {
+ handleResult(result, sendCommand)
+ }
+}
+thisRec.getActive().then(active => thisRec.setActive(!active));
\ No newline at end of file