{"version":3,"sources":["src/sdk/SpeakerRecognizer.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAmB,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EACH,kBAAkB,EAGlB,0BAA0B,EAC1B,wBAAwB,EAExB,wBAAwB,EAC3B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAEhE;;;;GAIG;AACH,qBAAa,iBAAiB;IAC1B,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC;IAC7C,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,mBAAmB,CAAkB;IAE7C;;;;;;OAMG;IACH,IAAW,kBAAkB,IAAI,MAAM,CAEtC;IAED;;;;;;OAMG;IACH,IAAW,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAG1C;IAED;;;;;;OAMG;IACH,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED;;;;OAIG;gBACgB,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW;IAWvE;;;;;;;;;OASG;IACU,kBAAkB,CAAC,KAAK,EAAE,0BAA0B,GAAG,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAahI;;;;;OAKG;IACI,KAAK,IAAI,IAAI;IAKpB,OAAO,CAAC,WAAW;YAoBL,SAAS;CAS1B","file":"SpeakerRecognizer.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n    IRestResponse,\r\n} from \"../common.browser/Exports\";\r\nimport {\r\n    Context,\r\n    OS,\r\n    SpeakerIdMessageAdapter,\r\n    SpeakerRecognitionConfig,\r\n} from \"../common.speech/Exports\";\r\nimport { marshalPromiseToCallbacks } from \"../common/Exports\";\r\nimport { AudioConfig, AudioConfigImpl } from \"./Audio/AudioConfig\";\r\nimport { Contracts } from \"./Contracts\";\r\nimport {\r\n    PropertyCollection,\r\n    PropertyId,\r\n    ResultReason,\r\n    SpeakerIdentificationModel,\r\n    SpeakerRecognitionResult,\r\n    SpeakerRecognitionResultType,\r\n    SpeakerVerificationModel,\r\n} from \"./Exports\";\r\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig\";\r\n\r\n/**\r\n * Defines SpeakerRecognizer class for Speaker Recognition\r\n * Handles operations from user for Voice Profile operations (e.g. createProfile, deleteProfile)\r\n * @class SpeakerRecognizer\r\n */\r\nexport class SpeakerRecognizer {\r\n    protected privProperties: PropertyCollection;\r\n    private privAdapter: SpeakerIdMessageAdapter;\r\n    private privAudioConfigImpl: AudioConfigImpl;\r\n\r\n    /**\r\n     * Gets the authorization token used to communicate with the service.\r\n     * @member SpeakerRecognizer.prototype.authorizationToken\r\n     * @function\r\n     * @public\r\n     * @returns {string} Authorization token.\r\n     */\r\n    public get authorizationToken(): string {\r\n        return this.properties.getProperty(PropertyId.SpeechServiceAuthorization_Token);\r\n    }\r\n\r\n    /**\r\n     * Gets/Sets the authorization token used to communicate with the service.\r\n     * @member SpeakerRecognizer.prototype.authorizationToken\r\n     * @function\r\n     * @public\r\n     * @param {string} token - Authorization token.\r\n     */\r\n    public set authorizationToken(token: string) {\r\n        Contracts.throwIfNullOrWhitespace(token, \"token\");\r\n        this.properties.setProperty(PropertyId.SpeechServiceAuthorization_Token, token);\r\n    }\r\n\r\n    /**\r\n     * The collection of properties and their values defined for this SpeakerRecognizer.\r\n     * @member SpeakerRecognizer.prototype.properties\r\n     * @function\r\n     * @public\r\n     * @returns {PropertyCollection} The collection of properties and their values defined for this SpeakerRecognizer.\r\n     */\r\n    public get properties(): PropertyCollection {\r\n        return this.privProperties;\r\n    }\r\n\r\n    /**\r\n     * SpeakerRecognizer constructor.\r\n     * @constructor\r\n     * @param {SpeechConfig} speechConfig - An set of initial properties for this recognizer (authentication key, region, &c)\r\n     */\r\n    public constructor(speechConfig: SpeechConfig, audioConfig: AudioConfig) {\r\n        const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\r\n        Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\r\n\r\n        this.privAudioConfigImpl = audioConfig as AudioConfigImpl;\r\n        Contracts.throwIfNull(this.privAudioConfigImpl, \"audioConfig\");\r\n\r\n        this.privProperties = speechConfigImpl.properties.clone();\r\n        this.implSRSetup();\r\n    }\r\n\r\n    /**\r\n     * Get recognition result for model using given audio\r\n     * @member SpeakerRecognizer.prototype.recognizeOnceAsync\r\n     * @function\r\n     * @public\r\n     * @async\r\n     * @param {SpeakerIdentificationModel} model Model containing Voice Profiles to be identified\r\n     * @param cb - Callback invoked once result is returned.\r\n     * @param err - Callback invoked in case of an error.\r\n     */\r\n    public async recognizeOnceAsync(model: SpeakerIdentificationModel | SpeakerVerificationModel): Promise<SpeakerRecognitionResult> {\r\n\r\n        if (model instanceof SpeakerIdentificationModel) {\r\n            const responsePromise: Promise<IRestResponse> = this.privAdapter.identifySpeaker(model, this.privAudioConfigImpl);\r\n            return this.getResult(responsePromise, SpeakerRecognitionResultType.Identify, undefined);\r\n        } else if (model instanceof SpeakerVerificationModel) {\r\n            const responsePromise: Promise<IRestResponse> = this.privAdapter.verifySpeaker(model, this.privAudioConfigImpl);\r\n            return this.getResult(responsePromise, SpeakerRecognitionResultType.Verify, model.voiceProfile.profileId);\r\n        } else {\r\n            throw new Error(\"SpeakerRecognizer.recognizeOnce: Unexpected model type\");\r\n        }\r\n    }\r\n\r\n    /**\r\n     * Included for compatibility\r\n     * @member SpeakerRecognizer.prototype.close\r\n     * @function\r\n     * @public\r\n     */\r\n    public close(): void {\r\n        return;\r\n    }\r\n\r\n    // Does class setup, swiped from Recognizer.\r\n    private implSRSetup(): void {\r\n\r\n        let osPlatform = (typeof window !== \"undefined\") ? \"Browser\" : \"Node\";\r\n        let osName = \"unknown\";\r\n        let osVersion = \"unknown\";\r\n\r\n        if (typeof navigator !== \"undefined\") {\r\n            osPlatform = osPlatform + \"/\" + navigator.platform;\r\n            osName = navigator.userAgent;\r\n            osVersion = navigator.appVersion;\r\n        }\r\n\r\n        const recognizerConfig =\r\n            new SpeakerRecognitionConfig(\r\n                new Context(new OS(osPlatform, osName, osVersion)),\r\n                this.privProperties);\r\n\r\n        this.privAdapter = new SpeakerIdMessageAdapter(recognizerConfig);\r\n    }\r\n\r\n    private async getResult(responsePromise: Promise<IRestResponse>, resultType: SpeakerRecognitionResultType, profileId?: string): Promise<SpeakerRecognitionResult> {\r\n        const response: IRestResponse = await responsePromise;\r\n        return new SpeakerRecognitionResult(\r\n            resultType,\r\n            response.data,\r\n            profileId,\r\n            response.ok ? ResultReason.RecognizedSpeaker : ResultReason.Canceled,\r\n        );\r\n    }\r\n}\r\n"]}