Ejemplo n.º 1
0
        /// <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(ServerGrammar g1, ServerGrammar g2 = null, ServerGrammar g3 = null, ServerGrammar g4 = null, ServerGrammar g5 = null,
                                   ServerGrammar g6 = null, ServerGrammar g7 = null, ServerGrammar g8 = null, ServerGrammar g9 = null, ServerGrammar 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 Microsoft.Speech.Recognition.GrammarBuilder[max];

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

            GrammarBuilder.Append(new Microsoft.Speech.Recognition.Choices(grammarBuilderArray));
        }
Ejemplo n.º 2
0
        public ServerGrammar NewGrammar()
        {
            var hg = new ServerGrammar();

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

            return(hg);
        }
Ejemplo n.º 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(ServerGrammar grammar, string name, dynamic callback)
        {
            _loadedGrammarDictionary.Add(name, new LoadedGrammar {
                Grammar = grammar, Callback = callback
            });
            var g = new Microsoft.Speech.Recognition.Grammar(grammar.GrammarBuilder)
            {
                Name = name
            };

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