{"version":3,"sources":["src/common.speech/SpeechContext.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,qBAAqB,EACxB,MAAM,cAAc,CAAC;AAMtB,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE3F;;;GAGG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,kBAAkB,CAAwB;gBAE/B,cAAc,EAAE,qBAAqB;IAIjD,UAAU,IAAI,oBAAoB;IAIzC;;;;OAIG;IACI,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAClD,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,GAAE,OAAe,GAAG,IAAI;IA8BhD,uBAAuB,IAAI,IAAI;IAgB/B,mBAAmB,IAAI,IAAI;IAmB3B,kCAAkC,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI;IAI/D,MAAM,IAAI,MAAM;CAQ1B","file":"SpeechContext.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n    DynamicGrammarBuilder,\n} from \"./Exports.js\";\nimport { Dgi } from \"./ServiceMessages/Dgi/Dgi.js\";\nimport { RecognitionMode } from \"./ServiceMessages/PhraseDetection/PhraseDetectionContext.js\";\nimport { OutputFormat, PhraseOption } from \"./ServiceMessages/PhraseOutput/PhraseOutput.js\";\nimport { PronunciationAssessmentOptions } from \"./ServiceMessages/PronunciationScore/PronunciationAssessmentOptions.js\";\n\nimport { SpeechContext as SpeechServiceContext } from \"./ServiceMessages/SpeechContext.js\";\n\n/**\n * Represents the JSON used in the speech.context message sent to the speech service.\n * The dynamic grammar is always refreshed from the encapsulated dynamic grammar object.\n */\nexport class SpeechContext {\n    private privContext: SpeechServiceContext = {};\n    private privDynamicGrammar: DynamicGrammarBuilder;\n\n    public constructor(dynamicGrammar: DynamicGrammarBuilder) {\n        this.privDynamicGrammar = dynamicGrammar;\n    }\n\n    public getContext(): SpeechServiceContext {\n        return this.privContext;\n    }\n\n    /**\n     * @Internal\n     * This is only used by pronunciation assessment config.\n     * Do not use externally, object returned will change without warning or notice.\n     */\n    public setPronunciationAssessmentParams(params: string,\n        contentAssessmentTopic: string,\n        isSpeakerDiarizationEnabled: boolean = false): void {\n        if (this.privContext.phraseDetection === undefined) {\n            this.privContext.phraseDetection = {\n                enrichment: {\n                    pronunciationAssessment: {}\n                }\n            };\n        }\n        if (this.privContext.phraseDetection.enrichment === undefined) {\n            this.privContext.phraseDetection.enrichment = {\n                pronunciationAssessment: {}\n            };\n        }\n        this.privContext.phraseDetection.enrichment.pronunciationAssessment = JSON.parse(params) as PronunciationAssessmentOptions || {};\n        if (isSpeakerDiarizationEnabled) {\n            this.privContext.phraseDetection.mode = RecognitionMode.Conversation;\n        }\n        this.setWordLevelTimings();\n        this.privContext.phraseOutput.detailed.options.push(PhraseOption.PronunciationAssessment);\n        if (this.privContext.phraseOutput.detailed.options.indexOf(PhraseOption.SNR) === -1) {\n            this.privContext.phraseOutput.detailed.options.push(PhraseOption.SNR);\n        }\n        if (!!contentAssessmentTopic) {\n            this.privContext.phraseDetection.enrichment.contentAssessment = {\n                topic: contentAssessmentTopic\n            };\n            this.privContext.phraseOutput.detailed.options.push(PhraseOption.ContentAssessment);\n        }\n    }\n\n    public setDetailedOutputFormat(): void {\n        if (this.privContext.phraseOutput === undefined) {\n            this.privContext.phraseOutput = {\n                detailed: {\n                    options: []\n                }\n            };\n        }\n        if (this.privContext.phraseOutput.detailed === undefined) {\n            this.privContext.phraseOutput.detailed = {\n                options: []\n            };\n        }\n        this.privContext.phraseOutput.format = OutputFormat.Detailed;\n    }\n\n    public setWordLevelTimings(): void {\n        if (this.privContext.phraseOutput === undefined) {\n            this.privContext.phraseOutput = {\n                detailed: {\n                    options: []\n                }\n            };\n        }\n        if (this.privContext.phraseOutput.detailed === undefined) {\n            this.privContext.phraseOutput.detailed = {\n                options: []\n            };\n        }\n        this.privContext.phraseOutput.format = OutputFormat.Detailed;\n        if (this.privContext.phraseOutput.detailed.options.indexOf(PhraseOption.WordTimings) === -1) {\n            this.privContext.phraseOutput.detailed.options.push(PhraseOption.WordTimings);\n        }\n    }\n\n    public setSpeakerDiarizationAudioOffsetMs(audioOffsetMs: number): void {\n        this.privContext.phraseDetection.speakerDiarization.audioOffsetMs = audioOffsetMs;\n    }\n\n    public toJSON(): string {\n\n        const dgi: Dgi = this.privDynamicGrammar.generateGrammarObject();\n        this.privContext.dgi = dgi;\n\n        const ret: string = JSON.stringify(this.privContext);\n        return ret;\n    }\n}\n"]}