UNPKG

@hahnpro/ms-speech-sdk

Version:
1 lines 5.13 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.\n// Licensed under the MIT license.\n\n/* eslint-disable max-classes-per-file */\nimport { CancellationErrorCodePropertyName, SpeakerResponse } from \"../common.speech/Exports.js\";\nimport {\n CancellationDetailsBase,\n CancellationErrorCode,\n CancellationReason,\n PropertyCollection,\n PropertyId,\n ResultReason,\n} from \"./Exports.js\";\n\nexport enum SpeakerRecognitionResultType {\n Verify,\n Identify\n}\n\n/**\n * Output format\n * @class SpeakerRecognitionResult\n */\nexport class SpeakerRecognitionResult {\n private privReason: ResultReason;\n private privProperties: PropertyCollection;\n private privProfileId: string;\n private privScore: number;\n private privErrorDetails: string;\n\n public constructor(response: SpeakerResponse, resultReason: ResultReason = ResultReason.RecognizedSpeaker, cancellationErrorCode: CancellationErrorCode = CancellationErrorCode.NoError, errorDetails: string = \"\") {\n this.privProperties = new PropertyCollection();\n const resultType = response.scenario === \"TextIndependentIdentification\" ? SpeakerRecognitionResultType.Identify : SpeakerRecognitionResultType.Verify;\n this.privReason = resultReason;\n if (this.privReason !== ResultReason.Canceled) {\n if (resultType === SpeakerRecognitionResultType.Identify) {\n this.privProfileId = response.identificationResult.identifiedProfile.profileId;\n this.privScore = response.identificationResult.identifiedProfile.score;\n this.privReason = ResultReason.RecognizedSpeakers;\n } else {\n this.privScore = response.verificationResult.score;\n if (response.verificationResult.recognitionResult.toLowerCase() !== \"accept\") {\n this.privReason = ResultReason.NoMatch;\n }\n if (response.verificationResult.profileId !== undefined && response.verificationResult.profileId !== \"\") {\n this.privProfileId = response.verificationResult.profileId;\n }\n }\n } else {\n this.privErrorDetails = errorDetails;\n this.privProperties.setProperty(CancellationErrorCodePropertyName, CancellationErrorCode[cancellationErrorCode]);\n }\n this.privProperties.setProperty(PropertyId.SpeechServiceResponse_JsonResult, JSON.stringify(response));\n }\n\n public get properties(): PropertyCollection {\n return this.privProperties;\n }\n\n public get reason(): ResultReason {\n return this.privReason;\n }\n\n public get profileId(): string {\n return this.privProfileId;\n }\n\n public get errorDetails(): string {\n return this.privErrorDetails;\n }\n\n public get score(): number {\n return this.privScore;\n }\n}\n\n/**\n * @class SpeakerRecognitionCancellationDetails\n */\nexport class SpeakerRecognitionCancellationDetails extends CancellationDetailsBase {\n\n private constructor(reason: CancellationReason, errorDetails: string, errorCode: CancellationErrorCode) {\n super(reason, errorDetails, errorCode);\n }\n\n /**\n * Creates an instance of SpeakerRecognitionCancellationDetails object for the canceled SpeakerRecognitionResult\n * @member SpeakerRecognitionCancellationDetails.fromResult\n * @function\n * @public\n * @param {SpeakerRecognitionResult} result - The result that was canceled.\n * @returns {SpeakerRecognitionCancellationDetails} The cancellation details object being created.\n */\n public static fromResult(result: SpeakerRecognitionResult): SpeakerRecognitionCancellationDetails {\n const reason = CancellationReason.Error;\n let errorCode: CancellationErrorCode = CancellationErrorCode.NoError;\n\n if (!!result.properties) {\n errorCode = CancellationErrorCode[result.properties.getProperty(CancellationErrorCodePropertyName, CancellationErrorCode[CancellationErrorCode.NoError]) as keyof typeof CancellationErrorCode];\n }\n\n return new SpeakerRecognitionCancellationDetails(reason, result.errorDetails, errorCode);\n }\n}\n"]}