UNPKG

@voice-ping/cognitive-services-speech

Version:

VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft

1 lines 5.07 kB
{"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.\n// Licensed under the MIT license.\n\nimport { CancellationErrorCodePropertyName } from \"../common.speech/Exports\";\nimport { Contracts } from \"./Contracts\";\nimport {\n CancellationDetailsBase,\n CancellationErrorCode,\n CancellationReason,\n PropertyCollection,\n PropertyId,\n ResultReason,\n} from \"./Exports\";\n\nexport enum SpeakerRecognitionResultType {\n Verify,\n Identify\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(resultType: SpeakerRecognitionResultType, data: string, profileId: string, resultReason: ResultReason = ResultReason.RecognizedSpeaker) {\n this.privProperties = new PropertyCollection();\n this.privReason = resultReason;\n if (this.privReason !== ResultReason.Canceled) {\n if (resultType === SpeakerRecognitionResultType.Identify) {\n const json: { identifiedProfile: { profileId: string, score: number } } = JSON.parse(data);\n Contracts.throwIfNullOrUndefined(json, \"JSON\");\n this.privProfileId = json.identifiedProfile.profileId;\n this.privScore = json.identifiedProfile.score;\n } else {\n const json: { recognitionResult: string, score: number } = JSON.parse(data);\n Contracts.throwIfNullOrUndefined(json, \"JSON\");\n this.privScore = json.score;\n if (json.recognitionResult.toLowerCase() !== \"accept\") {\n this.privReason = ResultReason.NoMatch;\n }\n if (profileId !== undefined && profileId !== \"\") {\n this.privProfileId = profileId;\n }\n }\n } else {\n const json: { statusText: string } = JSON.parse(data);\n Contracts.throwIfNullOrUndefined(json, \"JSON\");\n this.privErrorDetails = json.statusText;\n this.privProperties.setProperty(CancellationErrorCodePropertyName, CancellationErrorCode[CancellationErrorCode.ServiceError]);\n }\n this.privProperties.setProperty(PropertyId.SpeechServiceResponse_JsonResult, data);\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 */\n// tslint:disable-next-line:max-classes-per-file\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 as any)[result.properties.getProperty(CancellationErrorCodePropertyName, CancellationErrorCode[CancellationErrorCode.NoError])];\n }\n\n return new SpeakerRecognitionCancellationDetails(reason, result.errorDetails, errorCode);\n }\n}\n"]}