{"version":3,"sources":["src/common.speech/SpeechContext.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,qBAAqB,EAExB,MAAM,cAAc,CAAC;AAEtB,UAAU,OAAO;IACb,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC;CAC1B;AA2BD;;;GAGG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,kBAAkB,CAAwB;gBAE/B,cAAc,EAAE,qBAAqB;IAIxD;;;;OAIG;IACI,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAIxD;;;;OAIG;IACI,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAIrE;;;;OAIG;IACI,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAClD,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,GAAE,OAAe,GAAG,IAAI;IA8BhD,uBAAuB,IAAI,IAAI;IAiB/B,mBAAmB,IAAI,IAAI;IAoB3B,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.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n    DynamicGrammarBuilder,\r\n    IDynamicGrammar,\r\n} from \"./Exports.js\";\r\n\r\ninterface Context {\r\n    [section: string]: any;\r\n}\r\n\r\ninterface PhraseContext {\r\n    [section: string]: any;\r\n    phraseDetection?: {\r\n        enrichment?: {\r\n            pronunciationAssessment: any;\r\n            contentAssessment?: {\r\n                topic: string;\r\n            };\r\n        };\r\n        speakerDiarization?: {\r\n            mode?: string;\r\n            audioSessionId?: string;\r\n            audioOffsetMs?: number;\r\n            identityProvider?: string;\r\n        };\r\n        mode?: string;\r\n    };\r\n    phraseOutput?: {\r\n        detailed?: {\r\n            options?: string[];\r\n        };\r\n        format?: any;\r\n    };\r\n}\r\n\r\n/**\r\n * Represents the JSON used in the speech.context message sent to the speech service.\r\n * The dynamic grammar is always refreshed from the encapsulated dynamic grammar object.\r\n */\r\nexport class SpeechContext {\r\n    private privContext: PhraseContext = {};\r\n    private privDynamicGrammar: DynamicGrammarBuilder;\r\n\r\n    public constructor(dynamicGrammar: DynamicGrammarBuilder) {\r\n        this.privDynamicGrammar = dynamicGrammar;\r\n    }\r\n\r\n    /**\r\n     * Gets a section of the speech.context object.\r\n     * @param sectionName Name of the section to get.\r\n     * @return string or Context JSON serializable object that represents the value.\r\n     */\r\n    public getSection(sectionName: string): string | Context {\r\n        return (this.privContext[sectionName] || {}) as string | Context;\r\n    }\r\n\r\n    /**\r\n     * Adds a section to the speech.context object.\r\n     * @param sectionName Name of the section to add.\r\n     * @param value JSON serializable object that represents the value.\r\n     */\r\n    public setSection(sectionName: string, value: string | Context): void {\r\n        this.privContext[sectionName] = value;\r\n    }\r\n\r\n    /**\r\n     * @Internal\r\n     * This is only used by pronunciation assessment config.\r\n     * Do not use externally, object returned will change without warning or notice.\r\n     */\r\n    public setPronunciationAssessmentParams(params: string,\r\n        contentAssessmentTopic: string,\r\n        isSpeakerDiarizationEnabled: boolean = false): void {\r\n        if (this.privContext.phraseDetection === undefined) {\r\n            this.privContext.phraseDetection = {\r\n                enrichment: {\r\n                    pronunciationAssessment: {}\r\n                }\r\n            };\r\n        }\r\n        if (this.privContext.phraseDetection.enrichment === undefined) {\r\n            this.privContext.phraseDetection.enrichment = {\r\n                pronunciationAssessment: {}\r\n            };\r\n        }\r\n        this.privContext.phraseDetection.enrichment.pronunciationAssessment = JSON.parse(params) as Context;\r\n        if (isSpeakerDiarizationEnabled) {\r\n            this.privContext.phraseDetection.mode = \"Conversation\";\r\n        }\r\n        this.setWordLevelTimings();\r\n        this.privContext.phraseOutput.detailed.options.push(\"PronunciationAssessment\");\r\n        if (this.privContext.phraseOutput.detailed.options.indexOf(\"SNR\") === -1) {\r\n            this.privContext.phraseOutput.detailed.options.push(\"SNR\");\r\n        }\r\n        if (!!contentAssessmentTopic) {\r\n            this.privContext.phraseDetection.enrichment.contentAssessment = {\r\n                topic: contentAssessmentTopic\r\n            };\r\n            this.privContext.phraseOutput.detailed.options.push(\"ContentAssessment\");\r\n        }\r\n    }\r\n\r\n    public setDetailedOutputFormat(): void {\r\n        if (this.privContext.phraseOutput === undefined) {\r\n            this.privContext.phraseOutput = {\r\n                detailed: {\r\n                    options: []\r\n                },\r\n                format: {}\r\n            };\r\n        }\r\n        if (this.privContext.phraseOutput.detailed === undefined) {\r\n            this.privContext.phraseOutput.detailed = {\r\n                options: []\r\n            };\r\n        }\r\n        this.privContext.phraseOutput.format = \"Detailed\";\r\n    }\r\n\r\n    public setWordLevelTimings(): void {\r\n        if (this.privContext.phraseOutput === undefined) {\r\n            this.privContext.phraseOutput = {\r\n                detailed: {\r\n                    options: []\r\n                },\r\n                format: {}\r\n            };\r\n        }\r\n        if (this.privContext.phraseOutput.detailed === undefined) {\r\n            this.privContext.phraseOutput.detailed = {\r\n                options: []\r\n            };\r\n        }\r\n        this.privContext.phraseOutput.format = \"Detailed\";\r\n        if (this.privContext.phraseOutput.detailed.options.indexOf(\"WordTimings\") === -1) {\r\n            this.privContext.phraseOutput.detailed.options.push(\"WordTimings\");\r\n        }\r\n    }\r\n\r\n    public setSpeakerDiarizationAudioOffsetMs(audioOffsetMs: number): void {\r\n        this.privContext.phraseDetection.speakerDiarization.audioOffsetMs = audioOffsetMs;\r\n    }\r\n\r\n    public toJSON(): string {\r\n\r\n        const dgi: IDynamicGrammar = this.privDynamicGrammar.generateGrammarObject();\r\n        this.setSection(\"dgi\", dgi);\r\n\r\n        const ret: string = JSON.stringify(this.privContext);\r\n        return ret;\r\n    }\r\n}\r\n"]}