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AAkB,CAAC;IAKnF;;;;;;;;OAQG;IACU,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAKlF;;;;;OAKG;IACI,KAAK,IAAI,IAAI;IAKpB,SAAS,CAAC,eAAe,IAAI,IAAI;IAoBjC,OAAO,CAAC,SAAS;CAQpB","file":"VoiceProfileClient.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    VoiceProfile,\r\n    VoiceProfileEnrollmentResult,\r\n    VoiceProfilePhraseResult,\r\n    VoiceProfileResult,\r\n    VoiceProfileType,\r\n} from \"./Exports\";\r\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig\";\r\n\r\n/**\r\n * Defines VoiceProfileClient class for Speaker Recognition\r\n * Handles operations from user for Voice Profile operations (e.g. createProfile, deleteProfile)\r\n * @class VoiceProfileClient\r\n */\r\nexport class VoiceProfileClient {\r\n    protected privProperties: PropertyCollection;\r\n    private privAdapter: SpeakerIdMessageAdapter;\r\n\r\n    /**\r\n     * Gets the authorization token used to communicate with the service.\r\n     * @member VoiceProfileClient.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 VoiceProfileClient.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 VoiceProfileClient.\r\n     * @member VoiceProfileClient.prototype.properties\r\n     * @function\r\n     * @public\r\n     * @returns {PropertyCollection} The collection of properties and their values defined for this VoiceProfileClient.\r\n     */\r\n    public get properties(): PropertyCollection {\r\n        return this.privProperties;\r\n    }\r\n\r\n    /**\r\n     * VoiceProfileClient constructor.\r\n     * @constructor\r\n     * @param {SpeechConfig} speechConfig - An set of initial properties for this synthesizer (authentication key, region, &c)\r\n     */\r\n    public constructor(speechConfig: SpeechConfig) {\r\n        const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\r\n        Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\r\n\r\n        this.privProperties = speechConfigImpl.properties.clone();\r\n        this.implClientSetup();\r\n    }\r\n\r\n    /**\r\n     * Create a speaker recognition voice profile\r\n     * @member VoiceProfileClient.prototype.createProfileAsync\r\n     * @function\r\n     * @public\r\n     * @async\r\n     * @param {VoiceProfileType} profileType Type of Voice Profile to be created\r\n     *        specifies the keyword to be recognized.\r\n     * @param {string} lang Language string (locale) for Voice Profile\r\n     * @return {Promise<VoiceProfile>} - Promise of a VoiceProfile.\r\n     */\r\n    public async createProfileAsync(profileType: VoiceProfileType, lang: string): Promise<VoiceProfile> {\r\n        const result: IRestResponse = await this.privAdapter.createProfile(profileType, lang);\r\n        if (!result.ok) {\r\n            throw new Error(`createProfileAsync failed with code: ${result.status}, message: ${result.statusText}`);\r\n        }\r\n        const response: { profileId: string } = result.json;\r\n        const profile = new VoiceProfile(response.profileId, profileType);\r\n        return profile;\r\n    }\r\n    /**\r\n     * Get current information of a voice profile\r\n     * @member VoiceProfileClient.prototype.retrieveEnrollmentResultAsync\r\n     * @function\r\n     * @public\r\n     * @async\r\n     * @param {VoiceProfile} profile Voice Profile to retrieve info for\r\n     * @return {Promise<VoiceProfileEnrollmentResult>} - Promise of a VoiceProfileEnrollmentResult.\r\n     */\r\n    public async retrieveEnrollmentResultAsync(profile: VoiceProfile): Promise<VoiceProfileEnrollmentResult> {\r\n        const result: IRestResponse = await this.privAdapter.getProfileStatus(profile);\r\n        return new VoiceProfileEnrollmentResult(\r\n            result.ok ? ResultReason.EnrolledVoiceProfile : ResultReason.Canceled,\r\n            result.data,\r\n            result.statusText,\r\n        );\r\n    }\r\n\r\n    /**\r\n     * Get all voice profiles on account with given voice profile type\r\n     * @member VoiceProfileClient.prototype.getAllProfilesAsync\r\n     * @function\r\n     * @public\r\n     * @async\r\n     * @param {VoiceProfileType} profileType profile type (identification/verification) for which to list profiles\r\n     * @return {Promise<VoiceProfileEnrollmentResult[]>} - Promise of an array of VoiceProfileEnrollmentResults.\r\n     */\r\n    public async getAllProfilesAsync(profileType: VoiceProfileType): Promise<VoiceProfileEnrollmentResult[]> {\r\n        const result: IRestResponse = await this.privAdapter.getProfiles(profileType);\r\n        if (profileType === VoiceProfileType.TextIndependentIdentification) {\r\n            return VoiceProfileEnrollmentResult.FromIdentificationProfileList(result.json);\r\n        }\r\n        return VoiceProfileEnrollmentResult.FromVerificationProfileList(result.json);\r\n    }\r\n\r\n    /**\r\n     * Get valid authorization phrases for voice profile enrollment\r\n     * @member VoiceProfileClient.prototype.getAuthorizationPhrasesAsync\r\n     * @function\r\n     * @public\r\n     * @async\r\n     * @param {VoiceProfileType} profileType Profile Type to get activation phrases for\r\n     * @param {string} lang Language string (locale) for Voice Profile\r\n     */\r\n    public async getActivationPhrasesAsync(profileType: VoiceProfileType, lang: string): Promise<VoiceProfilePhraseResult> {\r\n        const result: IRestResponse = await this.privAdapter.getPhrases(profileType, lang);\r\n        return new VoiceProfilePhraseResult(\r\n            result.ok ? ResultReason.EnrollingVoiceProfile : ResultReason.Canceled,\r\n            result.statusText,\r\n            result.json\r\n        );\r\n    }\r\n\r\n    /**\r\n     * Create a speaker recognition voice profile\r\n     * @member VoiceProfileClient.prototype.enrollProfileAsync\r\n     * @function\r\n     * @public\r\n     * @async\r\n     * @param {VoiceProfile} profile Voice Profile to create enrollment for\r\n     * @param {AudioConfig} audioConfig source info from which to create enrollment\r\n     * @return {Promise<VoiceProfileEnrollmentResult>} - Promise of a VoiceProfileEnrollmentResult.\r\n     */\r\n    public async enrollProfileAsync(profile: VoiceProfile, audioConfig: AudioConfig): Promise<VoiceProfileEnrollmentResult> {\r\n        const configImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\r\n        Contracts.throwIfNullOrUndefined(configImpl, \"audioConfig\");\r\n\r\n        const result: IRestResponse = await this.privAdapter.createEnrollment(profile, configImpl);\r\n        return new VoiceProfileEnrollmentResult(\r\n            result.ok ? ResultReason.EnrolledVoiceProfile : ResultReason.Canceled,\r\n            result.data,\r\n            result.statusText,\r\n        );\r\n    }\r\n\r\n    /**\r\n     * Delete a speaker recognition voice profile\r\n     * @member VoiceProfileClient.prototype.deleteProfileAsync\r\n     * @function\r\n     * @public\r\n     * @async\r\n     * @param {VoiceProfile} profile Voice Profile to be deleted\r\n     * @return {Promise<VoiceProfileResult>} - Promise of a VoiceProfileResult.\r\n     */\r\n    public async deleteProfileAsync(profile: VoiceProfile): Promise<VoiceProfileResult> {\r\n        const result: IRestResponse = await this.privAdapter.deleteProfile(profile);\r\n        return this.getResult(result, ResultReason.DeletedVoiceProfile);\r\n    }\r\n\r\n    /**\r\n     * Remove all enrollments for a speaker recognition voice profile\r\n     * @member VoiceProfileClient.prototype.resetProfileAsync\r\n     * @function\r\n     * @public\r\n     * @async\r\n     * @param {VoiceProfile} profile Voice Profile to be reset\r\n     * @return {Promise<VoiceProfileResult>} - Promise of a VoiceProfileResult.\r\n     */\r\n    public async resetProfileAsync(profile: VoiceProfile): Promise<VoiceProfileResult> {\r\n        const result: IRestResponse = await this.privAdapter.resetProfile(profile);\r\n        return this.getResult(result, ResultReason.ResetVoiceProfile);\r\n    }\r\n\r\n    /**\r\n     * Included for compatibility\r\n     * @member VoiceProfileClient.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    protected implClientSetup(): 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 getResult(result: IRestResponse, successReason: ResultReason, cb?: (response: VoiceProfileResult) => void): VoiceProfileResult {\r\n        const response: VoiceProfileResult =\r\n            new VoiceProfileResult(\r\n                result.ok ? successReason : ResultReason.Canceled,\r\n                result.statusText\r\n            );\r\n        return (response);\r\n    }\r\n}\r\n"]}