set language property on TranslationRecognitionEventArgs (#736)

This commit is contained in:
Glenn Harper 2023-09-26 11:03:42 -07:00 коммит произвёл GitHub
Родитель 8cb9e719f9
Коммит 6848253d1d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -2,13 +2,14 @@
// Licensed under the MIT license.
import { Contracts } from "../../sdk/Contracts";
import { ITranslations } from "../Exports";
import { IPrimaryLanguage, ITranslations } from "../Exports";
import { TranslationStatus } from "../TranslationStatus";
// translation.hypothesis
export interface ITranslationHypothesis {
Duration: number;
Offset: number;
PrimaryLanguage?: IPrimaryLanguage;
Text: string;
Translation: ITranslations;
}
@ -48,4 +49,8 @@ export class TranslationHypothesis implements ITranslationHypothesis {
public get Translation(): ITranslations {
return this.privTranslationHypothesis.Translation;
}
public get Language(): string {
return this.privTranslationHypothesis.PrimaryLanguage?.Language;
}
}

Просмотреть файл

@ -336,7 +336,6 @@ export class TranslationServiceRecognizer extends ConversationServiceRecognizer
}
let resultReason: ResultReason;
let language: string;
let confidence: string;
if (serviceResult instanceof TranslationPhrase) {
if (!!serviceResult.Translation && serviceResult.Translation.TranslationStatus === TranslationStatus.Success) {
@ -344,11 +343,11 @@ export class TranslationServiceRecognizer extends ConversationServiceRecognizer
} else {
resultReason = ResultReason.RecognizedSpeech;
}
language = serviceResult.Language;
confidence = serviceResult.Confidence;
} else {
resultReason = ResultReason.TranslatingSpeech;
}
const language = serviceResult.Language;
const offset: number = serviceResult.Offset + this.privRequestSession.currentTurnAudioOffset;

Просмотреть файл

@ -492,6 +492,8 @@ describe.each([true, false])("Service based tests", (forceNodeWebSocket: boolean
expect(e.result.translations).not.toBeUndefined();
expect(e.result.translations.languages[0]).toEqual(defaultTargetLanguage);
expect(e.result.translations.get(defaultTargetLanguage)).toContain("Wie ist das");
expect(e.result.language).not.toBeUndefined();
expect(e.result.language).toEqual("en-US");
}
r.recognized = (o: sdk.Recognizer, e: sdk.TranslationRecognitionEventArgs) => {