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C;IAED,OAAO,CAAC,UAAU;CAwCrB","file":"PronunciationAssessmentConfig.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport { ServiceRecognizerBase } from \"../common.speech/ServiceRecognizerBase.js\";\nimport { Contracts } from \"./Contracts.js\";\nimport {\n PronunciationAssessmentGradingSystem,\n PronunciationAssessmentGranularity,\n PropertyCollection,\n PropertyId,\n Recognizer\n} from \"./Exports.js\";\n\ninterface PronunciationAssessmentJSON {\n referenceText: string;\n gradingSystem: string;\n granularity: string;\n phonemeAlphabet: string;\n nbestPhonemeCount: number;\n dimension: string;\n enableMiscue: boolean;\n enableProsodyAssessment: boolean;\n}\n\n/**\n * Pronunciation assessment configuration.\n * @class PronunciationAssessmentConfig\n * Added in version 1.15.0.\n */\nexport class PronunciationAssessmentConfig {\n private privProperties: PropertyCollection;\n private privPhonemeAlphabet: string;\n private privNBestPhonemeCount: number;\n private privEnableProsodyAssessment: boolean;\n private privContentAssessmentTopic: string;\n\n /**\n * PronunciationAssessmentConfig constructor.\n * @constructor\n * @param {string} referenceText\n * @param gradingSystem\n * @param granularity\n * @param enableMiscue\n */\n public constructor(referenceText: string,\n gradingSystem: PronunciationAssessmentGradingSystem = PronunciationAssessmentGradingSystem.FivePoint,\n granularity: PronunciationAssessmentGranularity = PronunciationAssessmentGranularity.Phoneme,\n enableMiscue: boolean = false) {\n Contracts.throwIfNullOrUndefined(referenceText, \"referenceText\");\n this.privProperties = new PropertyCollection();\n this.privProperties.setProperty(PropertyId.PronunciationAssessment_ReferenceText, referenceText);\n this.privProperties.setProperty(PropertyId.PronunciationAssessment_GradingSystem, PronunciationAssessmentGradingSystem[gradingSystem]);\n this.privProperties.setProperty(PropertyId.PronunciationAssessment_Granularity, PronunciationAssessmentGranularity[granularity]);\n this.privProperties.setProperty(PropertyId.PronunciationAssessment_EnableMiscue, String(enableMiscue));\n }\n\n /**\n * @member PronunciationAssessmentConfig.fromJSON\n * @function\n * @public\n * @param {string} json The json string containing the pronunciation assessment parameters.\n * @return {PronunciationAssessmentConfig} Instance of PronunciationAssessmentConfig\n * @summary Creates an instance of the PronunciationAssessmentConfig from json.\n * This method is designed to support the pronunciation assessment parameters still in preview.\n * Under normal circumstances, use the constructor instead.\n */\n public static fromJSON(json: string): PronunciationAssessmentConfig {\n Contracts.throwIfNullOrUndefined(json, \"json\");\n const config = new PronunciationAssessmentConfig(\"\");\n config.privProperties = new PropertyCollection();\n config.properties.setProperty(PropertyId.PronunciationAssessment_Json, json);\n return config;\n }\n\n public toJSON(): string {\n this.updateJson();\n return this.privProperties.getProperty(PropertyId.PronunciationAssessment_Params);\n }\n\n public applyTo(recognizer: Recognizer): void {\n this.updateJson();\n const recoBase = recognizer.internalData as ServiceRecognizerBase;\n recoBase.expectContentAssessmentResponse = !!this.privContentAssessmentTopic;\n recoBase.speechContext.setPronunciationAssessmentParams(\n this.properties.getProperty(PropertyId.PronunciationAssessment_Params),\n this.privContentAssessmentTopic,\n recoBase.isSpeakerDiarizationEnabled);\n }\n\n /**\n * Gets the reference text.\n * @member PronunciationAssessmentConfig.prototype.referenceText\n * @function\n * @public\n * @returns {string} Reference text.\n */\n public get referenceText(): string {\n return this.properties.getProperty(PropertyId.PronunciationAssessment_ReferenceText);\n }\n\n /**\n * Gets/Sets the reference text.\n * @member PronunciationAssessmentConfig.prototype.referenceText\n * @function\n * @public\n * @param {string} referenceText - Reference text.\n */\n public set referenceText(referenceText: string) {\n Contracts.throwIfNullOrWhitespace(referenceText, \"referenceText\");\n this.properties.setProperty(PropertyId.PronunciationAssessment_ReferenceText, referenceText);\n }\n\n /**\n * Sets the phoneme alphabet.\n * The valid values are \"SAPI\" (default) and \"IPA\".\n * Added in version 1.20.0\n * @member PronunciationAssessmentConfig.prototype.phonemeAlphabet\n * @function\n * @public\n * @param {string} phonemeAlphabet - Phoneme alphabet.\n */\n public set phonemeAlphabet(phonemeAlphabet: string) {\n Contracts.throwIfNullOrWhitespace(phonemeAlphabet, \"phonemeAlphabet\");\n this.privPhonemeAlphabet = phonemeAlphabet;\n }\n\n /**\n * Sets the boolean enableMiscue property.\n * Added in version 1.26.0\n * @member PronunciationAssessmentConfig.prototype.enableMiscue\n * @function\n * @public\n * @param {boolean} enableMiscue - enable miscue.\n */\n public set enableMiscue(enableMiscue: boolean) {\n const enableMiscueString = enableMiscue ? \"true\" : \"false\";\n this.properties.setProperty(PropertyId.PronunciationAssessment_EnableMiscue, enableMiscueString);\n }\n\n /**\n * Gets the boolean enableMiscue property.\n * Added in version 1.26.0\n * @member PronunciationAssessmentConfig.prototype.enableMiscue\n * @function\n * @public\n * @return {boolean} enableMiscue - enable miscue.\n */\n public get enableMiscue(): boolean {\n const enableMiscueString = this.properties.getProperty(PropertyId.PronunciationAssessment_EnableMiscue, \"false\");\n return (enableMiscueString.toLowerCase() === \"true\");\n }\n\n /**\n * Sets the nbest phoneme count\n * Added in version 1.20.0\n * @member PronunciationAssessmentConfig.prototype.nbestPhonemeCount\n * @function\n * @public\n * @param {number} nbestPhonemeCount - NBest phoneme count.\n */\n public set nbestPhonemeCount(nbestPhonemeCount: number) {\n this.privNBestPhonemeCount = nbestPhonemeCount;\n }\n\n /**\n * Enables the prosody assessment.\n * Added in version 1.34.0\n * @member PronunciationAssessmentConfig.prototype.enableProsodyAssessment\n * @function\n * @public\n * @param {boolean} enableProsodyAssessment - enable prosody assessment.\n */\n public set enableProsodyAssessment(enableProsodyAssessment: boolean) {\n this.privEnableProsodyAssessment = enableProsodyAssessment;\n }\n\n /**\n * Enables content assessment and sets the topic.\n * Added in version 1.34.0\n * @member PronunciationAssessmentConfig.prototype.enableContentAssessmentWithTopic\n * @function\n * @public\n * @param {string} topic - Topic for content assessment.\n */\n public enableContentAssessmentWithTopic(topic: string): void {\n this.privContentAssessmentTopic = topic;\n }\n\n /**\n * @member PronunciationAssessmentConfig.prototype.properties\n * @function\n * @public\n * @return {PropertyCollection} Properties of the config.\n * @summary Gets a pronunciation assessment config properties\n */\n public get properties(): PropertyCollection {\n return this.privProperties;\n }\n\n private updateJson(): void {\n const jsonString = this.privProperties.getProperty(PropertyId.PronunciationAssessment_Json, \"{}\");\n const paramsJson: PronunciationAssessmentJSON = JSON.parse(jsonString) as PronunciationAssessmentJSON;\n\n const referenceText = this.privProperties.getProperty(PropertyId.PronunciationAssessment_ReferenceText);\n if (referenceText) {\n paramsJson.referenceText = referenceText;\n }\n\n const gradingSystem = this.privProperties.getProperty(PropertyId.PronunciationAssessment_GradingSystem);\n if (gradingSystem) {\n paramsJson.gradingSystem = gradingSystem;\n }\n\n const granularity = this.privProperties.getProperty(PropertyId.PronunciationAssessment_Granularity);\n if (granularity) {\n paramsJson.granularity = granularity;\n }\n\n if (this.privPhonemeAlphabet) {\n paramsJson.phonemeAlphabet = this.privPhonemeAlphabet;\n }\n\n if (this.privNBestPhonemeCount) {\n paramsJson.nbestPhonemeCount = this.privNBestPhonemeCount;\n }\n\n paramsJson.enableProsodyAssessment = this.privEnableProsodyAssessment;\n\n // always set dimension to Comprehensive\n paramsJson.dimension = \"Comprehensive\";\n\n const enableMiscueString = this.privProperties.getProperty(PropertyId.PronunciationAssessment_EnableMiscue);\n if (enableMiscueString) {\n paramsJson.enableMiscue = this.enableMiscue;\n }\n\n this.privProperties.setProperty(PropertyId.PronunciationAssessment_Params, JSON.stringify(paramsJson));\n }\n\n}\n"]}