/// <summary>
        /// Adds one or more Grammars to this Grammar
        /// COM does not support Variable argument lists, so for now this method only support up to 10 parameters
        /// </summary>
        public void AppendGrammars(DesktopGrammar g1, DesktopGrammar g2 = null, DesktopGrammar g3 = null, DesktopGrammar g4 = null, DesktopGrammar g5 = null,
                                   DesktopGrammar g6 = null, DesktopGrammar g7 = null, DesktopGrammar g8 = null, DesktopGrammar g9 = null, DesktopGrammar g10 = null)
        {
            var grammars = new[] { g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 };
            var max      = -1;

            for (var i = 0; i < 10; i++)
            {
                if (grammars[i] == null)
                {
                    break;
                }
                max = i;
            }

            max++;

            var grammarBuilderArray = new System.Speech.Recognition.GrammarBuilder[max];

            for (var i = 0; i < max; i++)
            {
                grammarBuilderArray[i] = grammars[i].GrammarBuilder;
            }

            GrammarBuilder.Append(new System.Speech.Recognition.Choices(grammarBuilderArray));
        }
        public DesktopGrammar NewGrammar()
        {
            var hg = new DesktopGrammar();

            hg.GrammarBuilder.Culture = _recognizer.RecognizerInfo.Culture;

            return(hg);
        }
Beispiel #3
0
        /// <summary>
        /// Loads a Grammar object into the recognizer
        /// </summary>
        /// <param name="grammar"></param>
        /// <param name="name">The name to give the Grammar</param>
        /// <param name="callback">The code to fire when the Grammar is spoken</param>
        /// <returns></returns>
        public string LoadGrammar(DesktopGrammar grammar, string name, dynamic callback)
        {
            _loadedGrammarDictionary.Add(name, new LoadedGrammar {
                Grammar = grammar, Callback = callback
            });
            var g = new System.Speech.Recognition.Grammar(grammar.GrammarBuilder)
            {
                Name = name
            };

            _recognizer.LoadGrammar(g);
            return(grammar.GetPhrases());
        }