Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #122 from spokestack/jz-kw-timeout
Browse files Browse the repository at this point in the history
fix: timeout event when no keyword is recognized
  • Loading branch information
brentspell committed Dec 11, 2020
2 parents 9618e59 + 326b427 commit 771d085
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,17 +429,16 @@ private void detect(SpeechContext context) {

context.traceInfo("keyword: %.3f %s", confidence, transcript);

// if we are under threshold, return the null class
if (confidence < this.threshold) {
transcript = "";
confidence = 1.0f - confidence;
if (confidence >= this.threshold) {
// raise the speech recognition event with the class transcript
context.setTranscript(transcript);
context.setConfidence(confidence);
context.dispatch(SpeechContext.Event.RECOGNIZE);
} else {
// if we are under threshold, time out without recognition
context.dispatch(SpeechContext.Event.TIMEOUT);
}

// raise the speech recognition event with the class transcript
context.setTranscript(transcript);
context.setConfidence(confidence);
context.dispatch(SpeechContext.Event.RECOGNIZE);

reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void testRecSilentCtxActive() throws Exception {

@Test
public void testRecNullCtxDeactivate() throws Exception {
// verify that the null transcript is raised for the null class
// verify that a timeout is raised for the null class
TestEnv env = new TestEnv(testConfig());

env.context.setActive(true);
Expand All @@ -120,7 +120,7 @@ public void testRecNullCtxDeactivate() throws Exception {
env.context.setActive(false);
env.process();

assertEquals(SpeechContext.Event.RECOGNIZE, env.event);
assertEquals(SpeechContext.Event.TIMEOUT, env.event);
assertEquals("", env.context.getTranscript());
}

Expand Down

0 comments on commit 771d085

Please sign in to comment.