{"version":3,"sources":["src/sdk/PronunciationAssessmentConfig.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,oCAAoC,EACpC,kCAAkC,EAClC,kBAAkB,EAElB,UAAU,EACb,MAAM,WAAW,CAAC;AAEnB;;;;GAIG;AACH,qBAAa,6BAA6B;IACtC,OAAO,CAAC,cAAc,CAAqB;IAE3C;;;;;;;OAOG;gBACgB,aAAa,EAAE,MAAM,EACrB,aAAa,GAAE,oCAAqF,EACpG,WAAW,GAAE,kCAA+E,EAC5F,YAAY,GAAE,OAAe;IAShD;;;;;;;OAOG;WACW,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,6BAA6B;IAQ5D,MAAM,IAAI,MAAM;IAKhB,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAM5C;;;;;;OAMG;IACH,IAAW,aAAa,IAAI,MAAM,CAEjC;IAED;;;;;;OAMG;IACH,IAAW,aAAa,CAAC,aAAa,EAAE,MAAM,EAG7C;IAED;;;;;;OAMG;IACH,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED,OAAO,CAAC,UAAU;CAgCrB","file":"PronunciationAssessmentConfig.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport { ServiceRecognizerBase } from \"../common.speech/ServiceRecognizerBase\";\r\nimport { Contracts } from \"./Contracts\";\r\nimport {\r\n    PronunciationAssessmentGradingSystem,\r\n    PronunciationAssessmentGranularity,\r\n    PropertyCollection,\r\n    PropertyId,\r\n    Recognizer\r\n} from \"./Exports\";\r\n\r\n/**\r\n * Pronunciation assessment configuration.\r\n * @class PronunciationAssessmentConfig\r\n * Added in version 1.15.0.\r\n */\r\nexport class PronunciationAssessmentConfig {\r\n    private privProperties: PropertyCollection;\r\n\r\n    /**\r\n     * PronunciationAssessmentConfig constructor.\r\n     * @constructor\r\n     * @param {string} referenceText\r\n     * @param gradingSystem\r\n     * @param granularity\r\n     * @param enableMiscue\r\n     */\r\n    public constructor(referenceText: string,\r\n                       gradingSystem: PronunciationAssessmentGradingSystem = PronunciationAssessmentGradingSystem.FivePoint,\r\n                       granularity: PronunciationAssessmentGranularity = PronunciationAssessmentGranularity.Phoneme,\r\n                       enableMiscue: boolean = false) {\r\n        Contracts.throwIfNullOrUndefined(referenceText, \"referenceText\");\r\n        this.privProperties = new PropertyCollection();\r\n        this.privProperties.setProperty(PropertyId.PronunciationAssessment_ReferenceText, referenceText);\r\n        this.privProperties.setProperty(PropertyId.PronunciationAssessment_GradingSystem, PronunciationAssessmentGradingSystem[gradingSystem]);\r\n        this.privProperties.setProperty(PropertyId.PronunciationAssessment_Granularity, PronunciationAssessmentGranularity[granularity]);\r\n        this.privProperties.setProperty(PropertyId.PronunciationAssessment_EnableMiscue, String(enableMiscue));\r\n    }\r\n\r\n    /**\r\n     * @member PronunciationAssessmentConfig.fromJSON\r\n     * @function\r\n     * @public\r\n     * @param {string} json The json string containing the pronunciation assessment parameters.\r\n     * @return {PronunciationAssessmentConfig} Instance of PronunciationAssessmentConfig\r\n     * @summary Creates an instance of the PronunciationAssessmentConfig from json.\r\n     */\r\n    public static fromJSON(json: string): PronunciationAssessmentConfig {\r\n        Contracts.throwIfNullOrUndefined(json, \"json\");\r\n        const config = new PronunciationAssessmentConfig(\"\");\r\n        config.privProperties = new PropertyCollection();\r\n        config.properties.setProperty(PropertyId.PronunciationAssessment_Json, json);\r\n        return config;\r\n    }\r\n\r\n    public toJSON(): string {\r\n        this.updateJson();\r\n        return this.privProperties.getProperty(PropertyId.PronunciationAssessment_Params);\r\n    }\r\n\r\n    public applyTo(recognizer: Recognizer): void {\r\n        this.updateJson();\r\n        const recoBase = recognizer.internalData as ServiceRecognizerBase;\r\n        recoBase.speechContext.setPronunciationAssessmentParams(this.properties.getProperty(PropertyId.PronunciationAssessment_Params));\r\n    }\r\n\r\n    /**\r\n     * Gets the reference text.\r\n     * @member PronunciationAssessmentConfig.prototype.referenceText\r\n     * @function\r\n     * @public\r\n     * @returns {string} Reference text.\r\n     */\r\n    public get referenceText(): string {\r\n        return this.properties.getProperty(PropertyId.PronunciationAssessment_ReferenceText);\r\n    }\r\n\r\n    /**\r\n     * Gets/Sets the reference text.\r\n     * @member PronunciationAssessmentConfig.prototype.referenceText\r\n     * @function\r\n     * @public\r\n     * @param {string} referenceText - Reference text.\r\n     */\r\n    public set referenceText(referenceText: string) {\r\n        Contracts.throwIfNullOrWhitespace(referenceText, \"referenceText\");\r\n        this.properties.setProperty(PropertyId.PronunciationAssessment_ReferenceText, referenceText);\r\n    }\r\n\r\n    /**\r\n     * @member PronunciationAssessmentConfig.prototype.properties\r\n     * @function\r\n     * @public\r\n     * @return {PropertyCollection} Properties of the config.\r\n     * @summary Gets a pronunciation assessment config properties\r\n     */\r\n    public get properties(): PropertyCollection {\r\n        return this.privProperties;\r\n    }\r\n\r\n    private updateJson(): void {\r\n        const jsonString = this.privProperties.getProperty(PropertyId.PronunciationAssessment_Json, \"{}\");\r\n        const paramsJson = JSON.parse(jsonString);\r\n\r\n        const referenceText = this.privProperties.getProperty(PropertyId.PronunciationAssessment_ReferenceText);\r\n        if (referenceText) {\r\n            paramsJson.referenceText = referenceText;\r\n        }\r\n\r\n        const gradingSystem = this.privProperties.getProperty(PropertyId.PronunciationAssessment_GradingSystem);\r\n        if (gradingSystem) {\r\n            paramsJson.gradingSystem = gradingSystem;\r\n        }\r\n\r\n        const granularity = this.privProperties.getProperty(PropertyId.PronunciationAssessment_Granularity);\r\n        if (granularity) {\r\n            paramsJson.granularity = granularity;\r\n        }\r\n\r\n        // always set dimension to Comprehensive\r\n        paramsJson.dimension = \"Comprehensive\";\r\n\r\n        const enableMiscueString = this.privProperties.getProperty(PropertyId.PronunciationAssessment_EnableMiscue);\r\n        if (enableMiscueString === \"true\") {\r\n            paramsJson.enableMiscue = true;\r\n        } else if (enableMiscueString === \"false\") {\r\n            paramsJson.enableMiscue = false;\r\n        }\r\n\r\n        this.privProperties.setProperty(PropertyId.PronunciationAssessment_Params, JSON.stringify(paramsJson));\r\n    }\r\n\r\n}\r\n"]}