Skip to content

Commit

Permalink
Merge pull request #7 from Microsoft/fmegen/fix-event-ordering-end-of…
Browse files Browse the repository at this point in the history
…-stream

fire end of stream at turn.end, not at speech.end
  • Loading branch information
fmegen authored Dec 20, 2018
2 parents 12d5198 + 6d24401 commit 87b9d75
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/common.speech/ServiceRecognizerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export abstract class ServiceRecognizerBase implements IDisposable {
private privAuthFetchEventId: string;
private privIsDisposed: boolean;
private privRecognizer: Recognizer;
private privMustReportEndOfStream: boolean;
protected privRecognizerConfig: RecognizerConfig;

public constructor(
Expand All @@ -78,6 +79,7 @@ export abstract class ServiceRecognizerBase implements IDisposable {
throw new ArgumentNullError("recognizerConfig");
}

this.privMustReportEndOfStream = false;
this.privAuthentication = authentication;
this.privConnectionFactory = connectionFactory;
this.privAudioSource = audioSource;
Expand Down Expand Up @@ -318,6 +320,7 @@ export abstract class ServiceRecognizerBase implements IDisposable {
if (connectionMessage.requestId.toLowerCase() === requestSession.requestId.toLowerCase()) {
switch (connectionMessage.path.toLowerCase()) {
case "turn.start":
this.privMustReportEndOfStream = true;
break;
case "speech.startdetected":
const speechStartDetected: SpeechDetected = SpeechDetected.fromJSON(connectionMessage.textBody);
Expand Down Expand Up @@ -349,12 +352,13 @@ export abstract class ServiceRecognizerBase implements IDisposable {
if (!!this.privRecognizer.speechEndDetected) {
this.privRecognizer.speechEndDetected(this.privRecognizer, speechStopEventArgs);
}

if (requestSession.isSpeechEnded && this.privRecognizerConfig.isContinuousRecognition) {
this.cancelRecognitionLocal(requestSession, CancellationReason.EndOfStream, CancellationErrorCode.NoError, undefined, successCallback);
}
break;
case "turn.end":
if (requestSession.isSpeechEnded && this.privMustReportEndOfStream) {
this.privMustReportEndOfStream = false;
this.cancelRecognitionLocal(requestSession, CancellationReason.EndOfStream, CancellationErrorCode.NoError, undefined, successCallback);
}

const sessionStopEventArgs: SessionEventArgs = new SessionEventArgs(requestSession.sessionId);
requestSession.onServiceTurnEndResponse(this.privRecognizerConfig.isContinuousRecognition);
if (!this.privRecognizerConfig.isContinuousRecognition || requestSession.isSpeechEnded) {
Expand Down

0 comments on commit 87b9d75

Please sign in to comment.