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O,CAAC,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.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n IRestResponse\r\n} from \"../common.browser/Exports.js\";\r\nimport {\r\n IAuthentication,\r\n IConnectionFactory,\r\n RecognizerConfig,\r\n ServiceRecognizerBase,\r\n SpeechServiceConfig,\r\n VoiceProfileConnectionFactory,\r\n VoiceServiceRecognizer\r\n} from \"../common.speech/Exports.js\";\r\nimport { AudioConfig, AudioConfigImpl } from \"./Audio/AudioConfig.js\";\r\nimport { Contracts } from \"./Contracts.js\";\r\nimport {\r\n AudioInputStream,\r\n PropertyCollection,\r\n PropertyId,\r\n Recognizer,\r\n ResultReason,\r\n VoiceProfile,\r\n VoiceProfileEnrollmentResult,\r\n VoiceProfilePhraseResult,\r\n VoiceProfileResult,\r\n VoiceProfileType\r\n} from \"./Exports.js\";\r\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig.js\";\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 extends Recognizer {\r\n protected privProperties: PropertyCollection;\r\n private privVoiceAdapter: VoiceServiceRecognizer;\r\n private privDisposedVoiceAdapter: boolean;\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 Contracts.throwIfNullOrUndefined(speechConfig, \"speechConfig\");\r\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\r\n Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\r\n\r\n super(AudioConfig.fromStreamInput(AudioInputStream.createPushStream()), speechConfigImpl.properties, new VoiceProfileConnectionFactory());\r\n\r\n this.privProperties = speechConfigImpl.properties.clone();\r\n this.privVoiceAdapter = this.privReco as VoiceServiceRecognizer;\r\n this.privDisposedVoiceAdapter = false;\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 * 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 * 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 * @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 profileIds: string[] = await this.privVoiceAdapter.createProfile(profileType, lang);\r\n return new VoiceProfile(profileIds[0], profileType);\r\n }\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 return this.privVoiceAdapter.retrieveEnrollmentResult(profile);\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 return this.privVoiceAdapter.getAllProfiles(profileType);\r\n /*\r\n const result: { json: { value: EnrollmentResultJSON[] } } = 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 /**\r\n * Get valid authorization phrases for voice profile enrollment\r\n * @member VoiceProfileClient.prototype.getActivationPhrasesAsync\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 return this.privVoiceAdapter.getActivationPhrases(profileType, lang);\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 this.audioConfig = audioConfig;\r\n this.privVoiceAdapter.SpeakerAudioSource = configImpl;\r\n\r\n return this.privVoiceAdapter.enrollProfile(profile);\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 return this.privVoiceAdapter.deleteProfile(profile);\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 return this.privVoiceAdapter.resetProfile(profile);\r\n }\r\n\r\n /**\r\n * Clean up object and close underlying connection\r\n * @member VoiceProfileClient.prototype.close\r\n * @function\r\n * @async\r\n * @public\r\n */\r\n public async close(): Promise<void> {\r\n await this.dispose(true);\r\n }\r\n\r\n protected createServiceRecognizer(authentication: IAuthentication, connectionFactory: IConnectionFactory, audioConfig: AudioConfig, recognizerConfig: RecognizerConfig): ServiceRecognizerBase {\r\n const audioImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\r\n return new VoiceServiceRecognizer(authentication, connectionFactory, audioImpl, recognizerConfig, this);\r\n }\r\n\r\n protected async dispose(disposing: boolean): Promise<void> {\r\n if (this.privDisposedVoiceAdapter) {\r\n return;\r\n }\r\n\r\n this.privDisposedVoiceAdapter = true;\r\n\r\n if (disposing) {\r\n await super.dispose(disposing);\r\n }\r\n }\r\n\r\n protected createRecognizerConfig(speechConfig: SpeechServiceConfig): RecognizerConfig {\r\n return new RecognizerConfig(speechConfig, this.properties);\r\n }\r\n\r\n private getResult(result: IRestResponse, successReason: ResultReason): 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"]}