Skip to content

Commit

Permalink
Don't reuse variable names in telemetry verfication (#89)
Browse files Browse the repository at this point in the history
* Don't reuse variable names in telemetry verfication

* And now hypothesis

* When speech.end is detected, only shrink replay buffer for continuous recognition. Fix other bugs in telemetry verification code.

* Fix whitespace
  • Loading branch information
rhurey authored Sep 20, 2019
1 parent 2a1f238 commit 6c30e18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/common.speech/ServiceRecognizerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ export abstract class ServiceRecognizerBase implements IDisposable {

const speechStopDetected: SpeechDetected = SpeechDetected.fromJSON(json);

this.privRequestSession.onServiceRecognized(speechStopDetected.Offset + this.privRequestSession.currentTurnAudioOffset);
// Only shrink the buffers for continuous recognition.
// For single shot, the speech.phrase message will come after the speech.end and it should own buffer shrink.
if (this.privRecognizerConfig.isContinuousRecognition) {
this.privRequestSession.onServiceRecognized(speechStopDetected.Offset + this.privRequestSession.currentTurnAudioOffset);
}

const speechStopEventArgs = new RecognitionEventArgs(speechStopDetected.Offset + this.privRequestSession.currentTurnAudioOffset, this.privRequestSession.sessionId);

Expand Down
29 changes: 17 additions & 12 deletions tests/TelemetryUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,48 @@
import { IMetric, ITelemetry } from "../src/common.speech/ServiceTelemetryListener.Internal";
import { IStringDictionary } from "../src/common/IDictionary";

export const validateTelemetry: (json: string, phrases: number, hypothesis: number) => void = (json: string, phrases: number, hypothesis: number): void => {
export const validateTelemetry: (json: string, numPhrases: number, numHypothesis: number) => void = (json: string, numPhrases: number, numHypothesis: number): void => {
const telemetryMessage: ITelemetry = JSON.parse(json);

if (0 > phrases) {
if (0 < numPhrases) {
let phrases: string[] = telemetryMessage.ReceivedMessages["speech.phrase"];
if (undefined === phrases) {
phrases = telemetryMessage.ReceivedMessages["translation.phrase"];
}
expect(phrases.length).toEqual(phrases);
expect(phrases).not.toBeUndefined();
expect(phrases.length).toEqual(numPhrases);
}
if (0 > hypothesis) {
const hypothesis: string[] = telemetryMessage.ReceivedMessages["speech.hypothesis"];
expect(hypothesis.length).toEqual(hypothesis);

if (0 < numHypothesis) {
let hypothesis: string[] = telemetryMessage.ReceivedMessages["speech.hypothesis"];
if (undefined === hypothesis) {
hypothesis = telemetryMessage.ReceivedMessages["translation.hypothesis"];
}
expect(hypothesis.length).toEqual(numHypothesis);
}

let foundPhrases: number = 0;
for (const metric of telemetryMessage.Metrics) {
if (metric.PhraseLatencyMs !== undefined) {
foundPhrases++;
// For continuous recognition tests silence at the end my produce no last phrase.
expect(metric.PhraseLatencyMs.length).toBeLessThanOrEqual(phrases);
expect(metric.PhraseLatencyMs.length).toBeGreaterThanOrEqual(phrases - 1);
expect(metric.PhraseLatencyMs.length).toBeLessThanOrEqual(numPhrases);
expect(metric.PhraseLatencyMs.length).toBeGreaterThanOrEqual(numPhrases - 1);
}
}

expect(foundPhrases).toEqual(phrases === 0 ? 0 : 1);
expect(foundPhrases).toEqual(numPhrases === 0 ? 0 : 1);

let foundHypothesis: number = 0;
for (const metric of telemetryMessage.Metrics) {
if (metric.FirstHypothesisLatencyMs !== undefined) {
foundHypothesis++;

// For continuous recognition tests silence at the end my produce no hypothesis.
expect(metric.FirstHypothesisLatencyMs.length).toBeLessThanOrEqual(phrases);
expect(metric.FirstHypothesisLatencyMs.length).toBeGreaterThanOrEqual(phrases - 1);
expect(metric.FirstHypothesisLatencyMs.length).toBeLessThanOrEqual(numPhrases);
expect(metric.FirstHypothesisLatencyMs.length).toBeGreaterThanOrEqual(numPhrases - 1);
}
}

expect(foundHypothesis).toEqual(phrases === 0 ? 0 : 1);
expect(foundHypothesis).toEqual(numPhrases === 0 ? 0 : 1);
};

0 comments on commit 6c30e18

Please sign in to comment.