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

Commit

Permalink
fix: avoid timeout for empty Azure transcripts
Browse files Browse the repository at this point in the history
  • Loading branch information
space-pope committed Aug 10, 2021
1 parent 9bba8f3 commit f117558
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,13 @@ public void onEvent(
SpeechRecognitionEventArgs recognitionArgs) {
ResultReason reason = recognitionArgs.getResult().getReason();
String transcript = recognitionArgs.getResult().getText();
boolean isFinal = (reason == ResultReason.RecognizedSpeech);
if (!transcript.equals("")) {
if (isFinal) {
if (reason == ResultReason.RecognizedSpeech) {
dispatchResult(transcript, SpeechContext.Event.RECOGNIZE);
} else if (reason == ResultReason.RecognizingSpeech) {
dispatchResult(transcript,
SpeechContext.Event.PARTIAL_RECOGNIZE);
}
} else if (isFinal) {
this.speechContext.dispatch(SpeechContext.Event.TIMEOUT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class AzureSpeechRecognizerTest implements OnSpeechEventListener {
private SpeechRecognitionEventArgs partialRecognitionEvent;
private SpeechRecognitionEventArgs emptyTextEvent;
private SpeechRecognitionEventArgs recognitionEvent;
private SpeechRecognitionEventArgs timeoutEvent;
private SpeechRecognitionCanceledEventArgs canceledEvent;

@Before
Expand Down Expand Up @@ -100,13 +99,6 @@ public void setup() {
doReturn(ResultReason.RecognizedSpeech).when(finalResult).getReason();
when(recognitionEvent.getResult()).thenReturn(finalResult);

timeoutEvent = PowerMockito.mock(SpeechRecognitionEventArgs.class);
SpeechRecognitionResult timeoutResult =
mock(SpeechRecognitionResult.class);
doReturn("").when(timeoutResult).getText();
doReturn(ResultReason.RecognizedSpeech).when(timeoutResult).getReason();
when(timeoutEvent.getResult()).thenReturn(timeoutResult);

canceledEvent = PowerMockito.mock(SpeechRecognitionCanceledEventArgs.class);
doReturn(CancellationReason.Error).when(canceledEvent).getReason();
doReturn("unknown error").when(canceledEvent).getErrorDetails();
Expand Down Expand Up @@ -185,13 +177,6 @@ public void testListeners() {
assertEquals(1.0, context.getConfidence());
assertEquals(SpeechContext.Event.RECOGNIZE, this.event);

context.reset();
new AzureSpeechRecognizer.RecognitionListener(context)
.onEvent(mockRecognizer, timeoutEvent);
assertEquals("", context.getTranscript());
assertEquals(0.0, context.getConfidence());
assertEquals(SpeechContext.Event.TIMEOUT, this.event);

this.event = null;
new AzureSpeechRecognizer.RecognitionListener(context)
.onEvent(mockRecognizer, emptyTextEvent);
Expand Down

0 comments on commit f117558

Please sign in to comment.