当前位置: 首页>>代码示例>>C#>>正文


C# GrammarBuilder.Append方法代码示例

本文整理汇总了C#中GrammarBuilder.Append方法的典型用法代码示例。如果您正苦于以下问题:C# GrammarBuilder.Append方法的具体用法?C# GrammarBuilder.Append怎么用?C# GrammarBuilder.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GrammarBuilder的用法示例。


在下文中一共展示了GrammarBuilder.Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            var config = new JsonConfigHandler( System.IO.Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData ), "LeagueTag" ) );
            //config.Populate();
            config.Save();
            //config.Save(
            return;
            var engine = new SpeechRecognitionEngine();

            var builder = new GrammarBuilder();
            builder.Append( "tag" );
            builder.Append( new Choices( "baron", "dragon" ) );

            engine.RequestRecognizerUpdate();
            engine.LoadGrammar( new Grammar( builder ) );

            engine.SpeechRecognized += engine_SpeechRecognized;

            engine.SetInputToDefaultAudioDevice();
            engine.RecognizeAsync( RecognizeMode.Multiple );

            CompositionTarget.Rendering += CompositionTarget_Rendering;

            this.DataContext = this;
        }
开发者ID:upta,项目名称:LeagueTag,代码行数:27,代码来源:MainWindow.xaml.cs

示例2: GetGrammar_Custom

        public GrammarBuilder GetGrammar_Custom(string grammar)
        {
            Choices globalChoices = new Choices();
            string[] sentences = grammar.Split('|');
            foreach (string s in sentences)
            {
                GrammarBuilder sentenceBuilder = new GrammarBuilder();
                string[] words = s.Split(' ');
                foreach (string w in words)
                {
                    if (m_vocabulories.ContainsKey(w))
                        sentenceBuilder.Append(new Choices(m_vocabulories[w].ToArray()));
                    else if (w == "#Dictation")
                        sentenceBuilder.AppendDictation();
                    else if (w == "#WildCard")
                        sentenceBuilder.AppendWildcard();
                    else if (w != "")
                        sentenceBuilder.Append(w);
                }
                globalChoices.Add(sentenceBuilder);
            }

            GrammarBuilder globalBuilder = new GrammarBuilder(globalChoices);
            globalBuilder.Culture = m_culture;
            Console.WriteLine(globalBuilder.DebugShowPhrases);
            return globalBuilder;
        }
开发者ID:xufango,项目名称:contrib_bk,代码行数:27,代码来源:RobotGrammarManager.cs

示例3: addCommand

        private GrammarBuilder addCommand()
        {
            //<pleasantries> <command> <CLASS> <prep> <Time><year>
             //Pleasantries: I'd like to, please, I want to, would you
             //Command: Add, Remove
             //Class: a class, this class, that class, that other class
             //When: to Spring 2012

             Choices commands = new Choices();
             SemanticResultValue commandSRV;
             commandSRV = new SemanticResultValue("add", (int)CommandTypes.Add);
             commands.Add(commandSRV);
             commandSRV = new SemanticResultValue("take", (int)CommandTypes.Add);
             commands.Add(commandSRV);
             commandSRV = new SemanticResultValue("put", (int)CommandTypes.Add);
             commands.Add(commandSRV);
             SemanticResultKey commandSemKey = new SemanticResultKey(Slots.Command.ToString(), commands);

             // put the whole command together
             GrammarBuilder finalCommand = new GrammarBuilder();
             finalCommand.Append(this.pleasantries, 0, 1);
             finalCommand.Append(commandSemKey);
             finalCommand.Append(this.course, 0, 1);
             finalCommand.Append(this.semester, 0, 1);

             return finalCommand;
        }
开发者ID:ewhitmire,项目名称:mypack-speech,代码行数:27,代码来源:CommandGrammar.cs

示例4: BrightnessGrammar

        private Grammar BrightnessGrammar()
        {
            // Change/Set Brightness to Choices
            var choices = new Choices();
            for (var i = -255; i <= 255; i++)
            {
                SemanticResultValue choiceResultValue = new SemanticResultValue(i.ToString(), i);
                GrammarBuilder resultValueBuilder = new GrammarBuilder(choiceResultValue);
                choices.Add(resultValueBuilder);
            }

            GrammarBuilder changeGrammar = "Change";
            GrammarBuilder setGrammar = "Set";
            GrammarBuilder brightnessGrammar = "Brightness";
            GrammarBuilder toGrammar = "To";

            SemanticResultKey resultKey = new SemanticResultKey("brightness", choices);
            GrammarBuilder resultContrast = new GrammarBuilder(resultKey);

            Choices alternatives = new Choices(changeGrammar, setGrammar);

            GrammarBuilder result = new GrammarBuilder(alternatives);
            result.Append(brightnessGrammar);
            result.Append(toGrammar);
            result.Append(resultContrast);

            Grammar grammar = new Grammar(result);
            grammar.Name = "Set Brightness";
            return grammar;
        }
开发者ID:fvioz,项目名称:VoiceRecognition,代码行数:30,代码来源:MainView.cs

示例5: CreateAndLoadGrammarWithObjectsNames

        public void CreateAndLoadGrammarWithObjectsNames(string[] objNames)
        {
            // przesuwanie obiektow z wykorzystaniem nazw
            Choices objWithNames = new Choices(objNames);
            GrammarBuilder gbMOWN = new GrammarBuilder { Culture = recognizerInfo.Culture };
            gbMOWN.Append("move");
            gbMOWN.Append(new SemanticResultKey("OWN_MOVE_NAME", objWithNames));
            Grammar gMOWN = new Grammar(gbMOWN);

            // tworzenie obiektow z wykorzystaniem nazw, bez podawania kierunku
            GrammarBuilder gbCOWN = new GrammarBuilder { Culture = recognizerInfo.Culture };
            gbCOWN.Append("new");
            gbCOWN.Append(new SemanticResultKey("OWN_NEW_NAME", objWithNames));
            Grammar gCOWN = new Grammar(gbCOWN);

            // usuwanie obiektow z wykorzystaniem nazw
            GrammarBuilder gbROWN = new GrammarBuilder { Culture = recognizerInfo.Culture };
            gbROWN.Append("remove");
            gbROWN.Append(new SemanticResultKey("OWN_REMOVE_NAME", objWithNames));
            Grammar gROWN = new Grammar(gbROWN);

            // ladujemy wszystkie gramatyki
            speechEngine.LoadGrammar(gMOWN);
            speechEngine.LoadGrammar(gCOWN);
            speechEngine.LoadGrammar(gROWN);

            mainEngine.AddTextToLog("SpeechRec: " + "grammars loaded");
        }
开发者ID:KaMyLuS,项目名称:PTT-Kinect-Server,代码行数:28,代码来源:SpeechRecognizer.cs

示例6: GetSpellGrammar

        public GrammarBuilder GetSpellGrammar()
        {
            try
            {
                var dictationBuilder = new GrammarBuilder // creating a new grammar builder
                    {
                        Culture = new CultureInfo(Settings.CultureInfo)
                    };
                dictationBuilder.AppendDictation(); // append dictation to the created grammar builder

                var dictaphoneGb = new GrammarBuilder { Culture = new CultureInfo(Settings.CultureInfo) };
                dictaphoneGb.Append(new Choices("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"));

                var dictation = new GrammarBuilder { Culture = new CultureInfo(Settings.CultureInfo) };
                var length = Convert.ToInt32(ConfigurationManager.AppSettings.Get("SpellGrammarLength"));
                for (var i = 0; i < length; i++)
                {
                    dictation.Append(dictaphoneGb, 0, 200);
                    dictation.Append(dictationBuilder, 0 /* minimum repeat */, 10 /* maximum repeat*/ );
                }
                return dictation;
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex);
                throw;
            }
        }
开发者ID:prabash,项目名称:Voice-Based-Web-Browser,代码行数:28,代码来源:GrammarManager.cs

示例7: GetWebsiteNamesGrammar

        public GrammarBuilder GetWebsiteNamesGrammar()
        {
            try
            {
                Settings.CultureInfo = "en-GB";
                var webSiteNames = new List<string>();
                using (var fs = File.Open(VbwFileManager.FilePath() + "fnc_brwsr_websites" + VbwFileManager.FileExtension(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (var bs = new BufferedStream(fs))
                using (var sr = new StreamReader(bs))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        webSiteNames.Add(line);
                    }
                }

                var dictationBuilder = new GrammarBuilder // creating a new grammar builder
                    {
                        Culture = new CultureInfo(Settings.CultureInfo)
                    };
                dictationBuilder.AppendDictation(); // append dictation to the created grammar builder

                var dictaphoneGb = new GrammarBuilder { Culture = new CultureInfo(Settings.CultureInfo) };
                dictaphoneGb.Append(dictationBuilder, 0 /* minimum repeat */, 10 /* maximum repeat*/ );
                dictaphoneGb.Append(new Choices(webSiteNames.ToArray()));
                dictaphoneGb.Append(dictationBuilder, 0 /* minimum repeat */, 10 /* maximum repeat*/ );
                return dictaphoneGb;
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex);
                throw;
            }
        }
开发者ID:prabash,项目名称:Voice-Based-Web-Browser,代码行数:35,代码来源:GrammarManager.cs

示例8: BuildGrammar

        public Grammar BuildGrammar()
        {
            Choices choiceBuilder = new Choices();

            // Songs
            if (SongHelper.SongCount() > 0) // it freaks out if there's nothing in the one-of bit.
            {
                GrammarBuilder songBuilder = new GrammarBuilder();
                songBuilder.Append("play song");
                songBuilder.Append(SongHelper.GenerateSongChoices());
                choiceBuilder.Add(songBuilder);
            }

            GrammarBuilder shuffleBuilder = new GrammarBuilder();
            shuffleBuilder.Append("shuffle all songs");
            choiceBuilder.Add(shuffleBuilder);

            // Playlists
            if (SongHelper.PlaylistCount() > 0)
            {
                GrammarBuilder playListBuilder = new GrammarBuilder();
                playListBuilder.Append("play playlist");
                playListBuilder.Append(SongHelper.GeneratePlaylistChoices());
                choiceBuilder.Add(playListBuilder);

                GrammarBuilder shufflePlayListBuilder = new GrammarBuilder();
                shufflePlayListBuilder.Append("shuffle playlist");
                shufflePlayListBuilder.Append(SongHelper.GeneratePlaylistChoices());
                choiceBuilder.Add(shufflePlayListBuilder);
            }

            Grammar gram = new Grammar(new GrammarBuilder(choiceBuilder));

            return gram;
        }
开发者ID:BenWoodford,项目名称:Jarvis,代码行数:35,代码来源:Play.cs

示例9: CreateGrammar

        public void CreateGrammar()
        {
            // 1[what]  2[is today's, is tomorrow's, is the] 3[is today, is tomorrow]  4[time, day, date]  5[is it]

            var one = new Choices();
            one.Add(new SemanticResultValue("what", "what"));
            var sOne = new SemanticResultKey("one", one);

            var two = new Choices();
            two.Add(new SemanticResultValue("is today's", "is today"));
            two.Add(new SemanticResultValue("is tomorrow's", "is tomorrow"));
            two.Add(new SemanticResultValue("is the", "is the"));
            var sTwo = new SemanticResultKey("two", two);

            var three = new Choices();
            three.Add(new SemanticResultValue("is today", "is today"));
            three.Add(new SemanticResultValue("is tomorrow", "is tomorrow"));
            three.Add(new SemanticResultValue("was yesterday", "was yesterday"));
            var sThree = new SemanticResultKey("three", three);

            var four = new Choices();
            four.Add(new SemanticResultValue("time", "time"));
            four.Add(new SemanticResultValue("day", "day"));
            four.Add(new SemanticResultValue("date", "day"));
            var sFour = new SemanticResultKey("three", four);

            var five = new Choices();
            five.Add(new SemanticResultValue("is it", "is it"));
            var sFive = new SemanticResultKey("four", five);

            // what (time, day, date) is it
            var gOne = new GrammarBuilder();
            gOne.Append(sOne);
            gOne.Append(sFour);
            gOne.Append(sFive);

            // what (is today's, is the) (time, day, date)
            var gTwo = new GrammarBuilder();
            gTwo.Append(sOne);
            gTwo.Append(sTwo);
            gTwo.Append(sFour);

            // what (is today, is tomorrow)
            var gThree = new GrammarBuilder();
            gThree.Append(sOne);
            gThree.Append(sThree);

            var perm = new Choices();
            perm.Add(gOne);
            perm.Add(gTwo);
            perm.Add(gThree);

            var b = new GrammarBuilder();
            b.Append(perm, 0, 1);

            Grammar = new Grammar(b);
        }
开发者ID:EricFreeman,项目名称:HAL,代码行数:57,代码来源:DateAndTimeModule.cs

示例10: LoadGrammar

        private void LoadGrammar() {


            // Start Stop Listening            
            Choices c_StartStop = new Choices();
            c_StartStop.Add(new string[] { StartListeningText, StopListeningText });
            GrammarBuilder gb_StartStop = new GrammarBuilder();
            gb_StartStop.Append(c_StartStop);
            Grammar g_StartStop = new Grammar(gb_StartStop);


            // Create a simple grammar that recognizes "red", "green", or "blue".
            Choices colors = new Choices();
            colors.Add(new string[] { "red", "green", "blue", "white", "exit" , "Light On" , "Light Off" });
            // Create a GrammarBuilder object and append the Choices object.
            GrammarBuilder gb = new GrammarBuilder();            
            gb.Append(colors);
            // Create the Grammar instance and load it into the speech recognition engine.
            Grammar g_Comamnds = new Grammar(gb);
                        


            // numbers
            Choices ch_Numbers = new Choices();
            for(int i = 1; i<= 30; i++)
                ch_Numbers.Add(i.ToString());
            //ch_Numbers.Add("1");
            //ch_Numbers.Add("2");
            //ch_Numbers.Add("3");
            //ch_Numbers.Add("4"); // Technically Add(new string[] { "4" });
            //ch_Numbers.Add("30");
            //ch_Numbers.Add("13");
            GrammarBuilder gb_WhatIsXplusY = new GrammarBuilder();
            gb_WhatIsXplusY.Append("What is");
            gb_WhatIsXplusY.Append(ch_Numbers);
            gb_WhatIsXplusY.Append("plus");
            gb_WhatIsXplusY.Append(ch_Numbers);
            Grammar g_WhatIsXplusY = new Grammar(gb_WhatIsXplusY);


            // Build a Grammar object from the XML grammar.
            string fname = Application.StartupPath +"\\MediaMenuGrammar.grxml";
            if (!System.IO.File.Exists(fname))
                MessageBox.Show("Grammar File not found?" + Environment.NewLine + fname);
            
            Grammar g_mediaMusic = new Grammar(fname);
            


            recognizer.LoadGrammarAsync(g_StartStop);
            recognizer.LoadGrammarAsync(g_Comamnds);
            recognizer.LoadGrammarAsync(g_WhatIsXplusY);
            recognizer.LoadGrammarAsync(g_mediaMusic);


        }
开发者ID:MySmallProjectsUK,项目名称:VoiceCommandsSimple,代码行数:56,代码来源:Form1.cs

示例11: CreateGrammarBuilderFromTree

        public static GrammarBuilder CreateGrammarBuilderFromTree(RadTreeView treeView)
        {
            GrammarBuilder currentGrammar = new GrammarBuilder();
            currentGrammar.Append(new GrammarBuilder(Consts.NameOfTheGirl));

            Choices wholeGrammar = new Choices();
            for (int i = 0; i < treeView.Nodes.Count; ++i)
            {
                wholeGrammar.Add(MakeGrammarBuilderRecursively(treeView.Nodes[i]));
            }
            currentGrammar.Append(wholeGrammar);
            return new Choices(currentGrammar);
        }
开发者ID:ModernSteward,项目名称:ModernSteward,代码行数:13,代码来源:TreeViewToGrammarBuilderAlgorithm.cs

示例12: SpeechRecognition

        public SpeechRecognition()
        {
            InitializeComponent();

            GrammarBuilder grammar = new GrammarBuilder();
            grammar.Append(new Choices("red", "blue", "green", "black", "white"));
            grammar.Append(new Choices("on", "off"));
            
            recognizer.LoadGrammar(new Grammar(grammar));
            recognizer.SpeechDetected += recognizer_SpeechDetected;            
            recognizer.SpeechRecognized += recognizer_SpeechRecognized;
            recognizer.SpeechRecognitionRejected += recognizer_SpeechRejected;
            recognizer.SpeechHypothesized += recognizer_SpeechHypothesized;
        }
开发者ID:ittray,项目名称:LocalDemo,代码行数:14,代码来源:SpeechRecognition.xaml.cs

示例13: StartDesign

        public void StartDesign()
        {
            //In Process SpeewchRecognizer
            SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();

            recognizer.LoadGrammarCompleted += new EventHandler<LoadGrammarCompletedEventArgs>(LoadGrammarCompleted);
            recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognized);
            recognizer.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(SpeechRejected);
            recognizer.SetInputToDefaultAudioDevice();

            GrammarBuilder clear = new GrammarBuilder("Clear");

            GrammarBuilder insert = new GrammarBuilder("Insert");
            Choices gates = new Choices(new string[] { "and", "or", "not", "ex or", "nor", "nand" });
            Choices columns = new Choices(new string[] { "one", "too", "three", "four", "five", "six", "seven", "eight" });
            Choices rows = new Choices(new string[] { "one", "too", "three", "four", "five" });
            Choices orientation = new Choices(new string[] { "left", "right", "up", "down" });
            insert.Append(gates);
            insert.Append(columns);
            insert.Append(rows);
            insert.Append("towards");
            insert.Append(orientation);

            GrammarBuilder connect = new GrammarBuilder("Connect");
            connect.Append("output");
            connect.Append(columns);
            connect.Append(rows);
            connect.Append("to");
            connect.Append("input");
            connect.Append(columns);
            connect.Append(rows);

            Grammar _clear_grammar = new Grammar(clear);
            Grammar _insert_grammar = new Grammar(insert);
            Grammar _connect_grammar = new Grammar(connect);

            recognizer.LoadGrammarAsync(_clear_grammar);
            recognizer.LoadGrammarAsync(_insert_grammar);
            recognizer.LoadGrammarAsync(_connect_grammar);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());

            //recognizer.RecognizeAsync(RecognizeMode.Multiple);
            while (true)
            {
                recognizer.Recognize();
            }
        }
开发者ID:pratik09,项目名称:DigitalCircuitDesign,代码行数:49,代码来源:Circuit.cs

示例14: Main

        static void Main(string[] args)
        {
            // Create an in-process speech recognizer.
            using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new CultureInfo("en-US")))
            {
                // Create a grammar for choosing commandChoices for a flight.
                Choices commandChoices = new Choices(new string[] { "Lights On", "Lights Off", "All Off", "Say Time"});

                GrammarBuilder gb = new GrammarBuilder();
                gb.Append(Properties.Settings.Default.AssistantName);
                gb.Append(commandChoices);

                // Construct a Grammar object and load it to the recognizer.
                Grammar commandChooser = new Grammar(gb);
                commandChooser.Name = ("Command Chooser");
                recognizer.LoadGrammarAsync(commandChooser);

                // Attach event handlers.
                recognizer.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(SpeechDetectedHandler);
                recognizer.SpeechHypothesized += new EventHandler<SpeechHypothesizedEventArgs>(SpeechHypothesizedHandler);
                recognizer.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(SpeechRecognitionRejectedHandler);
                recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognizedHandler);
                recognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(RecognizeCompletedHandler);

                // Assign input to the recognizer and start asynchronous
                recognizer.SetInputToDefaultAudioDevice();

                _completed = false;
                Console.WriteLine("Starting asynchronous recognition...");
                //recognizer.RecognizeAsync(RecognizeMode.Multiple);

                recognizer.EmulateRecognizeAsync("Nigel Lights On");

                // Wait 30 seconds, and then cancel asynchronous recognition.
                Thread.Sleep(TimeSpan.FromSeconds(30));
                recognizer.RecognizeAsyncCancel();

                // Wait for the operation to complete.
                while (!_completed)
                {
                    Thread.Sleep(333);
                }
                Console.WriteLine("Done.");
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
开发者ID:bruceburge,项目名称:Nigel,代码行数:49,代码来源:Program.cs

示例15: CreateGrammar

        public void CreateGrammar()
        {
            var b = new GrammarBuilder();
            b.Append(Config.ComputerName);

            Grammar = new Grammar(b);
        }
开发者ID:EricFreeman,项目名称:HAL,代码行数:7,代码来源:StartListeningModule.cs


注:本文中的GrammarBuilder.Append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。