UNPKG

microsoft-cognitiveservices-speech-sdk

Version:
1 lines 5.34 kB
{"version":3,"sources":["src/sdk/SpeakerRecognitionResult.ts"],"names":[],"mappings":"AAIA,OAAO,EAAqC,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACjG,OAAO,EACH,uBAAuB,EACvB,qBAAqB,EAErB,kBAAkB,EAElB,YAAY,EACf,MAAM,cAAc,CAAC;AAEtB,oBAAY,4BAA4B;IACpC,MAAM,IAAA;IACN,QAAQ,IAAA;CACX;AAED;;;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,QAAQ,EAAE,eAAe,EAAE,YAAY,GAAE,YAA6C,EAAE,qBAAqB,GAAE,qBAAqD,EAAE,YAAY,GAAE,MAAW;IAyBlN,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;AACH,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\n/* eslint-disable max-classes-per-file */\r\nimport { CancellationErrorCodePropertyName, SpeakerResponse } from \"../common.speech/Exports.js\";\r\nimport {\r\n CancellationDetailsBase,\r\n CancellationErrorCode,\r\n CancellationReason,\r\n PropertyCollection,\r\n PropertyId,\r\n ResultReason,\r\n} from \"./Exports.js\";\r\n\r\nexport enum SpeakerRecognitionResultType {\r\n Verify,\r\n Identify\r\n}\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(response: SpeakerResponse, resultReason: ResultReason = ResultReason.RecognizedSpeaker, cancellationErrorCode: CancellationErrorCode = CancellationErrorCode.NoError, errorDetails: string = \"\") {\r\n this.privProperties = new PropertyCollection();\r\n const resultType = response.scenario === \"TextIndependentIdentification\" ? SpeakerRecognitionResultType.Identify : SpeakerRecognitionResultType.Verify;\r\n this.privReason = resultReason;\r\n if (this.privReason !== ResultReason.Canceled) {\r\n if (resultType === SpeakerRecognitionResultType.Identify) {\r\n this.privProfileId = response.identificationResult.identifiedProfile.profileId;\r\n this.privScore = response.identificationResult.identifiedProfile.score;\r\n this.privReason = ResultReason.RecognizedSpeakers;\r\n } else {\r\n this.privScore = response.verificationResult.score;\r\n if (response.verificationResult.recognitionResult.toLowerCase() !== \"accept\") {\r\n this.privReason = ResultReason.NoMatch;\r\n }\r\n if (response.verificationResult.profileId !== undefined && response.verificationResult.profileId !== \"\") {\r\n this.privProfileId = response.verificationResult.profileId;\r\n }\r\n }\r\n } else {\r\n this.privErrorDetails = errorDetails;\r\n this.privProperties.setProperty(CancellationErrorCodePropertyName, CancellationErrorCode[cancellationErrorCode]);\r\n }\r\n this.privProperties.setProperty(PropertyId.SpeechServiceResponse_JsonResult, JSON.stringify(response));\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\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[result.properties.getProperty(CancellationErrorCodePropertyName, CancellationErrorCode[CancellationErrorCode.NoError]) as keyof typeof CancellationErrorCode];\r\n }\r\n\r\n return new SpeakerRecognitionCancellationDetails(reason, result.errorDetails, errorCode);\r\n }\r\n}\r\n"]}