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IAW9H;;;;;;;;OAQG;IACI,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAW7H;;;;;OAKG;IACI,KAAK,IAAI,IAAI;IAKpB,SAAS,CAAC,eAAe,IAAI,IAAI;IAoBjC,OAAO,CAAC,qBAAqB;CAUhC","file":"VoiceProfileClient.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n    FileAudioSource,\n    IRestResponse,\n} from \"../common.browser/Exports\";\nimport {\n    Context,\n    OS,\n    SpeakerIdMessageAdapter,\n    SpeakerRecognitionConfig,\n} from \"../common.speech/Exports\";\nimport { IAudioSource, PromiseResult } from \"../common/Exports\";\nimport { AudioConfig, AudioConfigImpl } from \"./Audio/AudioConfig\";\nimport { Contracts } from \"./Contracts\";\nimport {\n    PropertyCollection,\n    PropertyId,\n    ResultReason,\n    VoiceProfile,\n    VoiceProfileEnrollmentResult,\n    VoiceProfileResult,\n    VoiceProfileType,\n} from \"./Exports\";\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig\";\n\n/**\n * Defines VoiceProfileClient class for Speaker Recognition\n * Handles operations from user for Voice Profile operations (e.g. createProfile, deleteProfile)\n * @class VoiceProfileClient\n */\nexport class VoiceProfileClient {\n    protected privProperties: PropertyCollection;\n    private privAdapter: SpeakerIdMessageAdapter;\n\n    /**\n     * Gets the authorization token used to communicate with the service.\n     * @member VoiceProfileClient.prototype.authorizationToken\n     * @function\n     * @public\n     * @returns {string} Authorization token.\n     */\n    public get authorizationToken(): string {\n        return this.properties.getProperty(PropertyId.SpeechServiceAuthorization_Token);\n    }\n\n    /**\n     * Gets/Sets the authorization token used to communicate with the service.\n     * @member VoiceProfileClient.prototype.authorizationToken\n     * @function\n     * @public\n     * @param {string} token - Authorization token.\n     */\n    public set authorizationToken(token: string) {\n        Contracts.throwIfNullOrWhitespace(token, \"token\");\n        this.properties.setProperty(PropertyId.SpeechServiceAuthorization_Token, token);\n    }\n\n    /**\n     * The collection of properties and their values defined for this VoiceProfileClient.\n     * @member VoiceProfileClient.prototype.properties\n     * @function\n     * @public\n     * @returns {PropertyCollection} The collection of properties and their values defined for this VoiceProfileClient.\n     */\n    public get properties(): PropertyCollection {\n        return this.privProperties;\n    }\n\n    /**\n     * VoiceProfileClient constructor.\n     * @constructor\n     * @param {SpeechConfig} speechConfig - An set of initial properties for this synthesizer (authentication key, region, &c)\n     */\n    public constructor(speechConfig: SpeechConfig) {\n        const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\n        Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\n\n        this.privProperties = speechConfigImpl.properties.clone();\n        this.implClientSetup();\n    }\n\n    /**\n     * Create a speaker recognition voice profile\n     * @member VoiceProfileClient.prototype.createProfileAsync\n     * @function\n     * @public\n     * @param {VoiceProfileType} profileType Type of Voice Profile to be created\n     *        specifies the keyword to be recognized.\n     * @param {string} lang Language string (locale) for Voice Profile\n     * @param cb - Callback invoked once Voice Profile has been created.\n     * @param err - Callback invoked in case of an error.\n     */\n    public createProfileAsync(profileType: VoiceProfileType, lang: string, cb?: (e: VoiceProfile) => void, err?: (e: string) => void): void {\n        this.privAdapter.createProfile(profileType, lang).on((result: IRestResponse) => {\n            if (!!cb) {\n                const response: { profileId: string } = result.json();\n                const profile = new VoiceProfile(response.profileId, profileType);\n                cb(profile);\n            }\n        },\n        (error: string) => {\n            if (!!err) {\n                err(error);\n            }\n        });\n    }\n\n    /**\n     * Create a speaker recognition voice profile\n     * @member VoiceProfileClient.prototype.enrollProfileAsync\n     * @function\n     * @public\n     * @param {VoiceProfile} profile Voice Profile to create enrollment for\n     * @param {AudioConfig} audioConfig source info from which to create enrollment\n     * @param cb - Callback invoked once Enrollment request has been submitted.\n     * @param err - Callback invoked in case of an error.\n     */\n    public enrollProfileAsync(profile: VoiceProfile, audioConfig: AudioConfig, cb?: (e: VoiceProfileEnrollmentResult) => void, err?: (e: string) => void): void {\n        const configImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\n        Contracts.throwIfNullOrUndefined(configImpl, \"audioConfig\");\n        this.privAdapter.createEnrollment(profile, configImpl).on((result: IRestResponse) => {\n            if (!!cb) {\n                cb(\n                    new VoiceProfileEnrollmentResult(\n                        result.ok ? ResultReason.EnrolledVoiceProfile : ResultReason.Canceled,\n                        result.data,\n                        result.statusText,\n                    )\n                );\n            }\n        },\n        (error: string) => {\n            if (!!err) {\n                err(error);\n            }\n        });\n    }\n\n    /**\n     * Delete a speaker recognition voice profile\n     * @member VoiceProfileClient.prototype.deleteProfileAsync\n     * @function\n     * @public\n     * @param {VoiceProfile} profile Voice Profile to be deleted\n     * @param cb - Callback invoked once Voice Profile has been deleted.\n     * @param err - Callback invoked in case of an error.\n     */\n    public deleteProfileAsync(profile: VoiceProfile, cb?: (response: VoiceProfileResult) => void, err?: (e: string) => void): void {\n        this.privAdapter.deleteProfile(profile).on((result: IRestResponse) => {\n            this.handleResultCallbacks(result, ResultReason.DeletedVoiceProfile, cb);\n        },\n        (error: string) => {\n            if (!!err) {\n                err(error);\n            }\n        });\n    }\n\n    /**\n     * Remove all enrollments for a speaker recognition voice profile\n     * @member VoiceProfileClient.prototype.resetProfileAsync\n     * @function\n     * @public\n     * @param {VoiceProfile} profile Voice Profile to be reset\n     * @param cb - Callback invoked once Voice Profile has been reset.\n     * @param err - Callback invoked in case of an error.\n     */\n    public resetProfileAsync(profile: VoiceProfile, cb?: (response: VoiceProfileResult) => void, err?: (e: string) => void): void {\n        this.privAdapter.resetProfile(profile).on((result: IRestResponse) => {\n            this.handleResultCallbacks(result, ResultReason.ResetVoiceProfile, cb);\n        },\n        (error: string) => {\n            if (!!err) {\n                err(error);\n            }\n        });\n    }\n\n    /**\n     * Included for compatibility\n     * @member VoiceProfileClient.prototype.close\n     * @function\n     * @public\n     */\n    public close(): void {\n        return;\n    }\n\n    // Does class setup, swiped from Recognizer.\n    protected implClientSetup(): void {\n\n        let osPlatform = (typeof window !== \"undefined\") ? \"Browser\" : \"Node\";\n        let osName = \"unknown\";\n        let osVersion = \"unknown\";\n\n        if (typeof navigator !== \"undefined\") {\n            osPlatform = osPlatform + \"/\" + navigator.platform;\n            osName = navigator.userAgent;\n            osVersion = navigator.appVersion;\n        }\n\n        const recognizerConfig =\n            new SpeakerRecognitionConfig(\n                new Context(new OS(osPlatform, osName, osVersion)),\n                this.privProperties);\n\n        this.privAdapter = new SpeakerIdMessageAdapter(recognizerConfig);\n    }\n\n    private handleResultCallbacks(result: IRestResponse, successReason: ResultReason, cb?: (response: VoiceProfileResult) => void): void {\n        if (!!cb) {\n            const response: VoiceProfileResult =\n                new VoiceProfileResult(\n                    result.ok ? successReason : ResultReason.Canceled,\n                    result.statusText\n                );\n            cb(response);\n        }\n    }\n}\n"]}