{"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.\n// Licensed under the MIT license.\n\nimport {\n    DynamicGrammarBuilder,\n    IDynamicGrammar,\n} from \"./Exports.js\";\n\ninterface Context {\n    [section: string]: any;\n}\n\ninterface PhraseContext {\n    [section: string]: any;\n    phraseDetection?: {\n        enrichment?: {\n            pronunciationAssessment: any;\n            contentAssessment?: {\n                topic: string;\n            };\n        };\n        speakerDiarization?: {\n            mode?: string;\n            audioSessionId?: string;\n            audioOffsetMs?: number;\n            identityProvider?: string;\n        };\n        mode?: string;\n    };\n    phraseOutput?: {\n        detailed?: {\n            options?: string[];\n        };\n        format?: any;\n    };\n}\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: PhraseContext = {};\n    private privDynamicGrammar: DynamicGrammarBuilder;\n\n    public constructor(dynamicGrammar: DynamicGrammarBuilder) {\n        this.privDynamicGrammar = dynamicGrammar;\n    }\n\n    /**\n     * Gets a section of the speech.context object.\n     * @param sectionName Name of the section to get.\n     * @return string or Context JSON serializable object that represents the value.\n     */\n    public getSection(sectionName: string): string | Context {\n        return (this.privContext[sectionName] || {}) as string | Context;\n    }\n\n    /**\n     * Adds a section to the speech.context object.\n     * @param sectionName Name of the section to add.\n     * @param value JSON serializable object that represents the value.\n     */\n    public setSection(sectionName: string, value: string | Context): void {\n        this.privContext[sectionName] = value;\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 Context;\n        if (isSpeakerDiarizationEnabled) {\n            this.privContext.phraseDetection.mode = \"Conversation\";\n        }\n        this.setWordLevelTimings();\n        this.privContext.phraseOutput.detailed.options.push(\"PronunciationAssessment\");\n        if (this.privContext.phraseOutput.detailed.options.indexOf(\"SNR\") === -1) {\n            this.privContext.phraseOutput.detailed.options.push(\"SNR\");\n        }\n        if (!!contentAssessmentTopic) {\n            this.privContext.phraseDetection.enrichment.contentAssessment = {\n                topic: contentAssessmentTopic\n            };\n            this.privContext.phraseOutput.detailed.options.push(\"ContentAssessment\");\n        }\n    }\n\n    public setDetailedOutputFormat(): void {\n        if (this.privContext.phraseOutput === undefined) {\n            this.privContext.phraseOutput = {\n                detailed: {\n                    options: []\n                },\n                format: {}\n            };\n        }\n        if (this.privContext.phraseOutput.detailed === undefined) {\n            this.privContext.phraseOutput.detailed = {\n                options: []\n            };\n        }\n        this.privContext.phraseOutput.format = \"Detailed\";\n    }\n\n    public setWordLevelTimings(): void {\n        if (this.privContext.phraseOutput === undefined) {\n            this.privContext.phraseOutput = {\n                detailed: {\n                    options: []\n                },\n                format: {}\n            };\n        }\n        if (this.privContext.phraseOutput.detailed === undefined) {\n            this.privContext.phraseOutput.detailed = {\n                options: []\n            };\n        }\n        this.privContext.phraseOutput.format = \"Detailed\";\n        if (this.privContext.phraseOutput.detailed.options.indexOf(\"WordTimings\") === -1) {\n            this.privContext.phraseOutput.detailed.options.push(\"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: IDynamicGrammar = this.privDynamicGrammar.generateGrammarObject();\n        this.setSection(\"dgi\", dgi);\n\n        const ret: string = JSON.stringify(this.privContext);\n        return ret;\n    }\n}\n"]}