1983d52d117d8fcee9b0e879232248ee59b98ce4e34061e6e7d189f9f1d36ca0.json 6.6 KB

1
  1. {"ast":null,"code":"\"use strict\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.DynamicGrammarBuilder = void 0;\n/**\n * Responsible for building the object to be sent to the speech service to support dynamic grammars.\n * @class DynamicGrammarBuilder\n */\nclass DynamicGrammarBuilder {\n // Adds one more reference phrases to the dynamic grammar to send.\n // All added phrases are generic phrases.\n addPhrase(phrase) {\n if (!this.privPhrases) {\n this.privPhrases = [];\n }\n if (phrase instanceof Array) {\n this.privPhrases = this.privPhrases.concat(phrase);\n } else {\n this.privPhrases.push(phrase);\n }\n }\n // Clears all phrases stored in the current object.\n clearPhrases() {\n this.privPhrases = undefined;\n }\n // Adds one or more reference grammars to the current grammar.\n addReferenceGrammar(grammar) {\n if (!this.privGrammars) {\n this.privGrammars = [];\n }\n if (grammar instanceof Array) {\n this.privGrammars = this.privGrammars.concat(grammar);\n } else {\n this.privGrammars.push(grammar);\n }\n }\n // clears all grammars stored on the recognizer.\n clearGrammars() {\n this.privGrammars = undefined;\n }\n // Generates an object that represents the dynamic grammar used by the Speech Service.\n // This is done by building an object with the correct layout based on the phrases and reference grammars added to this instance\n // of a DynamicGrammarBuilder\n generateGrammarObject() {\n if (this.privGrammars === undefined && this.privPhrases === undefined) {\n return undefined;\n }\n const retObj = {};\n retObj.ReferenceGrammars = this.privGrammars;\n if (undefined !== this.privPhrases && 0 !== this.privPhrases.length) {\n const retPhrases = [];\n this.privPhrases.forEach(value => {\n retPhrases.push({\n Text: value\n });\n });\n retObj.Groups = [{\n Type: \"Generic\",\n Items: retPhrases\n }];\n }\n return retObj;\n }\n}\nexports.DynamicGrammarBuilder = DynamicGrammarBuilder;","map":{"version":3,"names":["Object","defineProperty","exports","value","DynamicGrammarBuilder","addPhrase","phrase","privPhrases","Array","concat","push","clearPhrases","undefined","addReferenceGrammar","grammar","privGrammars","clearGrammars","generateGrammarObject","retObj","ReferenceGrammars","length","retPhrases","forEach","Text","Groups","Type","Items"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common.speech/DynamicGrammarBuilder.js"],"sourcesContent":["\"use strict\";\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.DynamicGrammarBuilder = void 0;\n/**\n * Responsible for building the object to be sent to the speech service to support dynamic grammars.\n * @class DynamicGrammarBuilder\n */\nclass DynamicGrammarBuilder {\n // Adds one more reference phrases to the dynamic grammar to send.\n // All added phrases are generic phrases.\n addPhrase(phrase) {\n if (!this.privPhrases) {\n this.privPhrases = [];\n }\n if (phrase instanceof Array) {\n this.privPhrases = this.privPhrases.concat(phrase);\n }\n else {\n this.privPhrases.push(phrase);\n }\n }\n // Clears all phrases stored in the current object.\n clearPhrases() {\n this.privPhrases = undefined;\n }\n // Adds one or more reference grammars to the current grammar.\n addReferenceGrammar(grammar) {\n if (!this.privGrammars) {\n this.privGrammars = [];\n }\n if (grammar instanceof Array) {\n this.privGrammars = this.privGrammars.concat(grammar);\n }\n else {\n this.privGrammars.push(grammar);\n }\n }\n // clears all grammars stored on the recognizer.\n clearGrammars() {\n this.privGrammars = undefined;\n }\n // Generates an object that represents the dynamic grammar used by the Speech Service.\n // This is done by building an object with the correct layout based on the phrases and reference grammars added to this instance\n // of a DynamicGrammarBuilder\n generateGrammarObject() {\n if (this.privGrammars === undefined && this.privPhrases === undefined) {\n return undefined;\n }\n const retObj = {};\n retObj.ReferenceGrammars = this.privGrammars;\n if (undefined !== this.privPhrases && 0 !== this.privPhrases.length) {\n const retPhrases = [];\n this.privPhrases.forEach((value) => {\n retPhrases.push({\n Text: value,\n });\n });\n retObj.Groups = [{ Type: \"Generic\", Items: retPhrases }];\n }\n return retObj;\n }\n}\nexports.DynamicGrammarBuilder = Dynamic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,iBAAiB,GAAG,IAAI,CAACJ,YAAY;IAC5C,IAAIH,SAAS,KAAK,IAAI,CAACL,WAAW,IAAI,CAAC,KAAK,IAAI,CAACA,WAAW,CAACa,MAAM,EAAE;MACjE,MAAMC,UAAU,GAAG,EAAE;MACrB,IAAI,CAACd,WAAW,CAACe,OAAO,CAAEnB,KAAK,IAAK;QAChCkB,UAAU,CAACX,IAAI,CAAC;UACZa,IAAI,EAAEpB;QACV,CAAC,CAAC;MACN,CAAC,CAAC;MACFe,MAAM,CAACM,MAAM,GAAG,CAAC;QAAEC,IAAI,EAAE,SAAS;QAAEC,KAAK,EAAEL;MAAW,CAAC,CAAC;IAC5D;IACA,OAAOH,MAAM;EACjB;AACJ;AACAhB,OAAO,CAACE,qBAAqB,GAAGA,qBAAqB","ignoreList":[]},"metadata":{},"sourceType":"script","externalDependencies":[]}