Skip to content

Commit

Permalink
callback for irredium
Browse files Browse the repository at this point in the history
  • Loading branch information
wasnoplus committed Sep 25, 2020
1 parent dff3399 commit 1f65982
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
const resultHandler = markWord;
const resetHandler = resetColors;
</script>
<script type="text/javascript" src="../script/resultHandling.js"></script>
<script type="text/javascript" src="resultHandle_demo.js"></script>
</head>
<body style='width: 100%; height: 100%'>
<table style='width: 100%; height: 100%'>
Expand Down
29 changes: 29 additions & 0 deletions demo/resultHandle_demo.js
Original file line number Diff line number Diff line change
@@ -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("<und>")) {
handleIt('<und>', 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);
}
}
}
18 changes: 10 additions & 8 deletions script/resultHandling.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// allWords = ['volgende', 'vorige']

const allWords = ['volgende', 'vorige']
const callbacks = [];
const eventWordMap = {
'vorige': 'navigate-backward',
Expand Down Expand Up @@ -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("<und>")) {
handleIt('<und>', 1);
}
}
}

function sendCommand(w, c) {
Expand All @@ -45,4 +39,12 @@ function sendCommand(w, c) {
callback(action);
}
}
}
}

thisRec = new VoskJS.Recognizer("model-nl.tar.gz")
thisRec.onresult = result => {
if (result.result) {
handleResult(result, sendCommand)
}
}
thisRec.getActive().then(active => thisRec.setActive(!active));

0 comments on commit 1f65982

Please sign in to comment.