microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 11.1 kB
Source Map (JSON)
{"version":3,"sources":["src/sdk/PronunciationAssessmentConfig.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,oCAAoC,EACpC,kCAAkC,EAClC,kBAAkB,EAElB,UAAU,EACb,MAAM,cAAc,CAAC;AAatB;;;;GAIG;AACH,qBAAa,6BAA6B;IACtC,OAAO,CAAC,cAAc,CAAqB;IAC3C,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,2BAA2B,CAAU;IAC7C,OAAO,CAAC,0BAA0B,CAAS;IAE3C;;;;;;;OAOG;gBACgB,aAAa,EAAE,MAAM,EACrB,aAAa,GAAE,oCAAqF,EACpG,WAAW,GAAE,kCAA+E,EAC5F,YAAY,GAAE,OAAe;IAShD;;;;;;;;;OASG;WACW,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,6BAA6B;IAQ5D,MAAM,IAAI,MAAM;IAKhB,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAU5C;;;;;;OAMG;IACH,IAAW,aAAa,IAAI,MAAM,CAEjC;IAED;;;;;;OAMG;IACH,IAAW,aAAa,CAAC,aAAa,EAAE,MAAM,EAG7C;IAED;;;;;;;;OAQG;IACH,IAAW,eAAe,CAAC,eAAe,EAAE,MAAM,EAGjD;IAED;;;;;;;OAOG;IACH,IAAW,YAAY,CAAC,YAAY,EAAE,OAAO,EAG5C;IAED;;;;;;;OAOG;IACH,IAAW,YAAY,IAAI,OAAO,CAGjC;IAED;;;;;;;OAOG;IACH,IAAW,iBAAiB,CAAC,iBAAiB,EAAE,MAAM,EAErD;IAED;;;;;;;OAOG;IACH,IAAW,uBAAuB,CAAC,uBAAuB,EAAE,OAAO,EAElE;IAED;;;;;;;OAOG;IACI,gCAAgC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI5D;;;;;;OAMG;IACH,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED,OAAO,CAAC,UAAU;CAwCrB","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.js\";\r\nimport { Contracts } from \"./Contracts.js\";\r\nimport {\r\n PronunciationAssessmentGradingSystem,\r\n PronunciationAssessmentGranularity,\r\n PropertyCollection,\r\n PropertyId,\r\n Recognizer\r\n} from \"./Exports.js\";\r\n\r\ninterface PronunciationAssessmentJSON {\r\n referenceText: string;\r\n gradingSystem: string;\r\n granularity: string;\r\n phonemeAlphabet: string;\r\n nbestPhonemeCount: number;\r\n dimension: string;\r\n enableMiscue: boolean;\r\n enableProsodyAssessment: boolean;\r\n}\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 private privPhonemeAlphabet: string;\r\n private privNBestPhonemeCount: number;\r\n private privEnableProsodyAssessment: boolean;\r\n private privContentAssessmentTopic: string;\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 * This method is designed to support the pronunciation assessment parameters still in preview.\r\n * Under normal circumstances, use the constructor instead.\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.expectContentAssessmentResponse = !!this.privContentAssessmentTopic;\r\n recoBase.speechContext.setPronunciationAssessmentParams(\r\n this.properties.getProperty(PropertyId.PronunciationAssessment_Params),\r\n this.privContentAssessmentTopic,\r\n recoBase.isSpeakerDiarizationEnabled);\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 * Sets the phoneme alphabet.\r\n * The valid values are \"SAPI\" (default) and \"IPA\".\r\n * Added in version 1.20.0\r\n * @member PronunciationAssessmentConfig.prototype.phonemeAlphabet\r\n * @function\r\n * @public\r\n * @param {string} phonemeAlphabet - Phoneme alphabet.\r\n */\r\n public set phonemeAlphabet(phonemeAlphabet: string) {\r\n Contracts.throwIfNullOrWhitespace(phonemeAlphabet, \"phonemeAlphabet\");\r\n this.privPhonemeAlphabet = phonemeAlphabet;\r\n }\r\n\r\n /**\r\n * Sets the boolean enableMiscue property.\r\n * Added in version 1.26.0\r\n * @member PronunciationAssessmentConfig.prototype.enableMiscue\r\n * @function\r\n * @public\r\n * @param {boolean} enableMiscue - enable miscue.\r\n */\r\n public set enableMiscue(enableMiscue: boolean) {\r\n const enableMiscueString = enableMiscue ? \"true\" : \"false\";\r\n this.properties.setProperty(PropertyId.PronunciationAssessment_EnableMiscue, enableMiscueString);\r\n }\r\n\r\n /**\r\n * Gets the boolean enableMiscue property.\r\n * Added in version 1.26.0\r\n * @member PronunciationAssessmentConfig.prototype.enableMiscue\r\n * @function\r\n * @public\r\n * @return {boolean} enableMiscue - enable miscue.\r\n */\r\n public get enableMiscue(): boolean {\r\n const enableMiscueString = this.properties.getProperty(PropertyId.PronunciationAssessment_EnableMiscue, \"false\");\r\n return (enableMiscueString.toLowerCase() === \"true\");\r\n }\r\n\r\n /**\r\n * Sets the nbest phoneme count\r\n * Added in version 1.20.0\r\n * @member PronunciationAssessmentConfig.prototype.nbestPhonemeCount\r\n * @function\r\n * @public\r\n * @param {number} nbestPhonemeCount - NBest phoneme count.\r\n */\r\n public set nbestPhonemeCount(nbestPhonemeCount: number) {\r\n this.privNBestPhonemeCount = nbestPhonemeCount;\r\n }\r\n\r\n /**\r\n * Enables the prosody assessment.\r\n * Added in version 1.34.0\r\n * @member PronunciationAssessmentConfig.prototype.enableProsodyAssessment\r\n * @function\r\n * @public\r\n * @param {boolean} enableProsodyAssessment - enable prosody assessment.\r\n */\r\n public set enableProsodyAssessment(enableProsodyAssessment: boolean) {\r\n this.privEnableProsodyAssessment = enableProsodyAssessment;\r\n }\r\n\r\n /**\r\n * Enables content assessment and sets the topic.\r\n * Added in version 1.34.0\r\n * @member PronunciationAssessmentConfig.prototype.enableContentAssessmentWithTopic\r\n * @function\r\n * @public\r\n * @param {string} topic - Topic for content assessment.\r\n */\r\n public enableContentAssessmentWithTopic(topic: string): void {\r\n this.privContentAssessmentTopic = topic;\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: PronunciationAssessmentJSON = JSON.parse(jsonString) as PronunciationAssessmentJSON;\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 if (this.privPhonemeAlphabet) {\r\n paramsJson.phonemeAlphabet = this.privPhonemeAlphabet;\r\n }\r\n\r\n if (this.privNBestPhonemeCount) {\r\n paramsJson.nbestPhonemeCount = this.privNBestPhonemeCount;\r\n }\r\n\r\n paramsJson.enableProsodyAssessment = this.privEnableProsodyAssessment;\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) {\r\n paramsJson.enableMiscue = this.enableMiscue;\r\n }\r\n\r\n this.privProperties.setProperty(PropertyId.PronunciationAssessment_Params, JSON.stringify(paramsJson));\r\n }\r\n\r\n}\r\n"]}