microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 4.98 kB
Source Map (JSON)
{"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,EAAE,2BAA2B,GAAE,OAAe,GAAG,IAAI;IAwBpG,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.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n DynamicGrammarBuilder,\r\n} from \"./Exports.js\";\r\nimport { Dgi } from \"./ServiceMessages/Dgi/Dgi.js\";\r\nimport { RecognitionMode } from \"./ServiceMessages/PhraseDetection/PhraseDetectionContext.js\";\r\nimport { OutputFormat, PhraseOption } from \"./ServiceMessages/PhraseOutput/PhraseOutput.js\";\r\nimport { PronunciationAssessmentOptions } from \"./ServiceMessages/PronunciationScore/PronunciationAssessmentOptions.js\";\r\n\r\nimport { SpeechContext as SpeechServiceContext } from \"./ServiceMessages/SpeechContext.js\";\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: SpeechServiceContext = {};\r\n private privDynamicGrammar: DynamicGrammarBuilder;\r\n\r\n public constructor(dynamicGrammar: DynamicGrammarBuilder) {\r\n this.privDynamicGrammar = dynamicGrammar;\r\n }\r\n\r\n public getContext(): SpeechServiceContext {\r\n return this.privContext;\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, 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 PronunciationAssessmentOptions || {};\r\n if (isSpeakerDiarizationEnabled) {\r\n this.privContext.phraseDetection.mode = RecognitionMode.Conversation;\r\n }\r\n this.setWordLevelTimings();\r\n this.privContext.phraseOutput.detailed.options.push(PhraseOption.PronunciationAssessment);\r\n if (this.privContext.phraseOutput.detailed.options.indexOf(PhraseOption.SNR) === -1) {\r\n this.privContext.phraseOutput.detailed.options.push(PhraseOption.SNR);\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 };\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 = OutputFormat.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 };\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 = OutputFormat.Detailed;\r\n if (this.privContext.phraseOutput.detailed.options.indexOf(PhraseOption.WordTimings) === -1) {\r\n this.privContext.phraseOutput.detailed.options.push(PhraseOption.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: Dgi = this.privDynamicGrammar.generateGrammarObject();\r\n this.privContext.dgi = dgi;\r\n\r\n const ret: string = JSON.stringify(this.privContext);\r\n return ret;\r\n }\r\n}\r\n"]}