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AAC,wBAAwB,CAAC;IAItH;;;;;;;;;OASG;IACU,kBAAkB,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,4BAA4B,CAAC;IASvH;;;;;;;;OAQG;IACU,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAInF;;;;;;;;OAQG;IACU,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIlF;;;;;;OAMG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC,SAAS,CAAC,uBAAuB,CAAC,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,qBAAqB;cAK9K,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1D,SAAS,CAAC,sBAAsB,CAAC,YAAY,EAAE,mBAAmB,GAAG,gBAAgB;IAIrF,OAAO,CAAC,SAAS;CAQpB","file":"VoiceProfileClient.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n IRestResponse\n} from \"../common.browser/Exports.js\";\nimport {\n IAuthentication,\n IConnectionFactory,\n RecognizerConfig,\n ServiceRecognizerBase,\n SpeechServiceConfig,\n VoiceProfileConnectionFactory,\n VoiceServiceRecognizer\n} from \"../common.speech/Exports.js\";\nimport { AudioConfig, AudioConfigImpl } from \"./Audio/AudioConfig.js\";\nimport { Contracts } from \"./Contracts.js\";\nimport {\n AudioInputStream,\n PropertyCollection,\n PropertyId,\n Recognizer,\n ResultReason,\n VoiceProfile,\n VoiceProfileEnrollmentResult,\n VoiceProfilePhraseResult,\n VoiceProfileResult,\n VoiceProfileType\n} from \"./Exports.js\";\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig.js\";\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 extends Recognizer {\n protected privProperties: PropertyCollection;\n private privVoiceAdapter: VoiceServiceRecognizer;\n private privDisposedVoiceAdapter: boolean;\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 Contracts.throwIfNullOrUndefined(speechConfig, \"speechConfig\");\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\n Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\n\n super(AudioConfig.fromStreamInput(AudioInputStream.createPushStream()), speechConfigImpl.properties, new VoiceProfileConnectionFactory());\n\n this.privProperties = speechConfigImpl.properties.clone();\n this.privVoiceAdapter = this.privReco as VoiceServiceRecognizer;\n this.privDisposedVoiceAdapter = false;\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 * 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 * Create a speaker recognition voice profile\n * @member VoiceProfileClient.prototype.createProfileAsync\n * @function\n * @public\n * @async\n * @param {VoiceProfileType} profileType Type of Voice Profile to be created\n * @param {string} lang Language string (locale) for Voice Profile\n * @return {Promise<VoiceProfile>} - Promise of a VoiceProfile.\n */\n public async createProfileAsync(profileType: VoiceProfileType, lang: string): Promise<VoiceProfile> {\n const profileIds: string[] = await this.privVoiceAdapter.createProfile(profileType, lang);\n return new VoiceProfile(profileIds[0], profileType);\n }\n\n /**\n * Get current information of a voice profile\n * @member VoiceProfileClient.prototype.retrieveEnrollmentResultAsync\n * @function\n * @public\n * @async\n * @param {VoiceProfile} profile Voice Profile to retrieve info for\n * @return {Promise<VoiceProfileEnrollmentResult>} - Promise of a VoiceProfileEnrollmentResult.\n */\n public async retrieveEnrollmentResultAsync(profile: VoiceProfile): Promise<VoiceProfileEnrollmentResult> {\n return this.privVoiceAdapter.retrieveEnrollmentResult(profile);\n }\n\n /**\n * Get all voice profiles on account with given voice profile type\n * @member VoiceProfileClient.prototype.getAllProfilesAsync\n * @function\n * @public\n * @async\n * @param {VoiceProfileType} profileType profile type (identification/verification) for which to list profiles\n * @return {Promise<VoiceProfileEnrollmentResult[]>} - Promise of an array of VoiceProfileEnrollmentResults.\n */\n public async getAllProfilesAsync(profileType: VoiceProfileType): Promise<VoiceProfileEnrollmentResult[]> {\n return this.privVoiceAdapter.getAllProfiles(profileType);\n /*\n const result: { json: { value: EnrollmentResultJSON[] } } = await this.privAdapter.getProfiles(profileType);\n if (profileType === VoiceProfileType.TextIndependentIdentification) {\n return VoiceProfileEnrollmentResult.FromIdentificationProfileList(result.json);\n }\n return VoiceProfileEnrollmentResult.FromVerificationProfileList(result.json);\n */\n }\n\n /**\n * Get valid authorization phrases for voice profile enrollment\n * @member VoiceProfileClient.prototype.getActivationPhrasesAsync\n * @function\n * @public\n * @async\n * @param {VoiceProfileType} profileType Profile Type to get activation phrases for\n * @param {string} lang Language string (locale) for Voice Profile\n */\n public async getActivationPhrasesAsync(profileType: VoiceProfileType, lang: string): Promise<VoiceProfilePhraseResult> {\n return this.privVoiceAdapter.getActivationPhrases(profileType, lang);\n }\n\n /**\n * Create a speaker recognition voice profile\n * @member VoiceProfileClient.prototype.enrollProfileAsync\n * @function\n * @public\n * @async\n * @param {VoiceProfile} profile Voice Profile to create enrollment for\n * @param {AudioConfig} audioConfig source info from which to create enrollment\n * @return {Promise<VoiceProfileEnrollmentResult>} - Promise of a VoiceProfileEnrollmentResult.\n */\n public async enrollProfileAsync(profile: VoiceProfile, audioConfig: AudioConfig): Promise<VoiceProfileEnrollmentResult> {\n const configImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\n Contracts.throwIfNullOrUndefined(configImpl, \"audioConfig\");\n this.audioConfig = audioConfig;\n this.privVoiceAdapter.SpeakerAudioSource = configImpl;\n\n return this.privVoiceAdapter.enrollProfile(profile);\n }\n\n /**\n * Delete a speaker recognition voice profile\n * @member VoiceProfileClient.prototype.deleteProfileAsync\n * @function\n * @public\n * @async\n * @param {VoiceProfile} profile Voice Profile to be deleted\n * @return {Promise<VoiceProfileResult>} - Promise of a VoiceProfileResult.\n */\n public async deleteProfileAsync(profile: VoiceProfile): Promise<VoiceProfileResult> {\n return this.privVoiceAdapter.deleteProfile(profile);\n }\n\n /**\n * Remove all enrollments for a speaker recognition voice profile\n * @member VoiceProfileClient.prototype.resetProfileAsync\n * @function\n * @public\n * @async\n * @param {VoiceProfile} profile Voice Profile to be reset\n * @return {Promise<VoiceProfileResult>} - Promise of a VoiceProfileResult.\n */\n public async resetProfileAsync(profile: VoiceProfile): Promise<VoiceProfileResult> {\n return this.privVoiceAdapter.resetProfile(profile);\n }\n\n /**\n * Clean up object and close underlying connection\n * @member VoiceProfileClient.prototype.close\n * @function\n * @async\n * @public\n */\n public async close(): Promise<void> {\n await this.dispose(true);\n }\n\n protected createServiceRecognizer(authentication: IAuthentication, connectionFactory: IConnectionFactory, audioConfig: AudioConfig, recognizerConfig: RecognizerConfig): ServiceRecognizerBase {\n const audioImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\n return new VoiceServiceRecognizer(authentication, connectionFactory, audioImpl, recognizerConfig, this);\n }\n\n protected async dispose(disposing: boolean): Promise<void> {\n if (this.privDisposedVoiceAdapter) {\n return;\n }\n\n this.privDisposedVoiceAdapter = true;\n\n if (disposing) {\n await super.dispose(disposing);\n }\n }\n\n protected createRecognizerConfig(speechConfig: SpeechServiceConfig): RecognizerConfig {\n return new RecognizerConfig(speechConfig, this.properties);\n }\n\n private getResult(result: IRestResponse, successReason: ResultReason): VoiceProfileResult {\n const response: VoiceProfileResult =\n new VoiceProfileResult(\n result.ok ? successReason : ResultReason.Canceled,\n result.statusText\n );\n return (response);\n }\n}\n"]}