{"version":3,"sources":["src/sdk/SpeakerRecognitionResult.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,uBAAuB,EAGvB,kBAAkB,EAElB,YAAY,EACf,MAAM,WAAW,CAAC;AAEnB,oBAAY,4BAA4B;IACpC,MAAM,IAAA;IACN,QAAQ,IAAA;CACX;AACD;;;GAGG;AACH,qBAAa,wBAAwB;IACjC,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,cAAc,CAAqB;IAC3C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,gBAAgB,CAAS;gBAEd,UAAU,EAAE,4BAA4B,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAE,YAA6C;IA6BzJ,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED,IAAW,MAAM,IAAI,YAAY,CAEhC;IAED,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED,IAAW,KAAK,IAAI,MAAM,CAEzB;CACJ;AAED;;GAEG;AAEH,qBAAa,qCAAsC,SAAQ,uBAAuB;IAE9E,OAAO;IAIP;;;;;;;OAOG;WACW,UAAU,CAAC,MAAM,EAAE,wBAAwB,GAAG,qCAAqC;CAUpG","file":"SpeakerRecognitionResult.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport { CancellationErrorCodePropertyName } from \"../common.speech/Exports\";\r\nimport { Contracts } from \"./Contracts\";\r\nimport {\r\n    CancellationDetailsBase,\r\n    CancellationErrorCode,\r\n    CancellationReason,\r\n    PropertyCollection,\r\n    PropertyId,\r\n    ResultReason,\r\n} from \"./Exports\";\r\n\r\nexport enum SpeakerRecognitionResultType {\r\n    Verify,\r\n    Identify\r\n}\r\n/**\r\n * Output format\r\n * @class SpeakerRecognitionResult\r\n */\r\nexport class SpeakerRecognitionResult {\r\n    private privReason: ResultReason;\r\n    private privProperties: PropertyCollection;\r\n    private privProfileId: string;\r\n    private privScore: number;\r\n    private privErrorDetails: string;\r\n\r\n    public constructor(resultType: SpeakerRecognitionResultType, data: string, profileId: string, resultReason: ResultReason = ResultReason.RecognizedSpeaker) {\r\n        this.privProperties = new PropertyCollection();\r\n        this.privReason = resultReason;\r\n        if (this.privReason !== ResultReason.Canceled) {\r\n            if (resultType === SpeakerRecognitionResultType.Identify) {\r\n                const json: { identifiedProfile: { profileId: string, score: number } } = JSON.parse(data);\r\n                Contracts.throwIfNullOrUndefined(json, \"JSON\");\r\n                this.privProfileId = json.identifiedProfile.profileId;\r\n                this.privScore = json.identifiedProfile.score;\r\n            } else {\r\n                const json: { recognitionResult: string, score: number } = JSON.parse(data);\r\n                Contracts.throwIfNullOrUndefined(json, \"JSON\");\r\n                this.privScore = json.score;\r\n                if (json.recognitionResult.toLowerCase() !== \"accept\") {\r\n                    this.privReason = ResultReason.NoMatch;\r\n                }\r\n                if (profileId !== undefined && profileId !== \"\") {\r\n                    this.privProfileId = profileId;\r\n                }\r\n            }\r\n        } else {\r\n            const json: { statusText: string } = JSON.parse(data);\r\n            Contracts.throwIfNullOrUndefined(json, \"JSON\");\r\n            this.privErrorDetails = json.statusText;\r\n            this.privProperties.setProperty(CancellationErrorCodePropertyName, CancellationErrorCode[CancellationErrorCode.ServiceError]);\r\n        }\r\n        this.privProperties.setProperty(PropertyId.SpeechServiceResponse_JsonResult, data);\r\n    }\r\n\r\n    public get properties(): PropertyCollection {\r\n        return this.privProperties;\r\n    }\r\n\r\n    public get reason(): ResultReason {\r\n        return this.privReason;\r\n    }\r\n\r\n    public get profileId(): string {\r\n        return this.privProfileId;\r\n    }\r\n\r\n    public get errorDetails(): string {\r\n        return this.privErrorDetails;\r\n    }\r\n\r\n    public get score(): number {\r\n        return this.privScore;\r\n    }\r\n}\r\n\r\n/**\r\n * @class SpeakerRecognitionCancellationDetails\r\n */\r\n// tslint:disable-next-line:max-classes-per-file\r\nexport class SpeakerRecognitionCancellationDetails extends CancellationDetailsBase {\r\n\r\n    private constructor(reason: CancellationReason, errorDetails: string, errorCode: CancellationErrorCode) {\r\n        super(reason, errorDetails, errorCode);\r\n    }\r\n\r\n    /**\r\n     * Creates an instance of SpeakerRecognitionCancellationDetails object for the canceled SpeakerRecognitionResult\r\n     * @member SpeakerRecognitionCancellationDetails.fromResult\r\n     * @function\r\n     * @public\r\n     * @param {SpeakerRecognitionResult} result - The result that was canceled.\r\n     * @returns {SpeakerRecognitionCancellationDetails} The cancellation details object being created.\r\n     */\r\n    public static fromResult(result: SpeakerRecognitionResult): SpeakerRecognitionCancellationDetails {\r\n        const reason = CancellationReason.Error;\r\n        let errorCode: CancellationErrorCode = CancellationErrorCode.NoError;\r\n\r\n        if (!!result.properties) {\r\n            errorCode = (CancellationErrorCode as any)[result.properties.getProperty(CancellationErrorCodePropertyName, CancellationErrorCode[CancellationErrorCode.NoError])];\r\n        }\r\n\r\n        return new SpeakerRecognitionCancellationDetails(reason, result.errorDetails, errorCode);\r\n    }\r\n}\r\n"]}