Ejemplo n.º 1
0
        public void WriteStronglyTypedGrammarToXml()
        {
            SrgsDocument srgsDoc = CreateSrgsDocument();

            var builder = new StringBuilder();

            using (XmlWriter writer = XmlWriter.Create(builder))
            {
                srgsDoc.WriteSrgs(writer);
            }

            Assert.Contains("someRule", builder.ToString());
        }
Ejemplo n.º 2
0
        private Grammar init()
        {
            SrgsRule  ruleImie = new SrgsRule("Imię");
            SrgsOneOf imie     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, "Damian"),
                new SrgsItem(1, 1, "Jan"),
                new SrgsItem(1, 1, "Katarzyna"),
                new SrgsItem(1, 1, "Paweł"),
                new SrgsItem(1, 1, "Adam"),
                new SrgsItem(1, 1, "Maciej"),
                new SrgsItem(1, 1, "Maja"),
                new SrgsItem(1, 1, "Grzegorz")
            });

            ruleImie.Add(imie);

            SrgsRule  ruleNazwisko = new SrgsRule("Nazwisko");
            SrgsOneOf nazwisko     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, "Redkiewicz"),
                new SrgsItem(1, 1, "Piechota"),
                new SrgsItem(1, 1, "Klatka"),
                new SrgsItem(1, 1, "Kowalski"),
                new SrgsItem(1, 1, "Nowak"),
                new SrgsItem(1, 1, "Brzęczyszczykiewicz")
            });

            ruleNazwisko.Add(nazwisko);

            SrgsRule rootRule = new SrgsRule("rootBiletomat");

            rootRule.Scope = SrgsRuleScope.Public;
            rootRule.Add(new SrgsRuleRef(ruleImie, "IMIE"));
            rootRule.Add(new SrgsRuleRef(ruleNazwisko, "NAZWISKO"));

            SrgsDocument docBiletomat = new SrgsDocument();

            docBiletomat.Culture = pRecognitionLanguage;
            docBiletomat.Rules.Add(new SrgsRule[]
                                   { rootRule, ruleImie, ruleNazwisko }
                                   );
            docBiletomat.Root = rootRule;
            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("srgsDocument.xml");
            docBiletomat.WriteSrgs(writer);
            writer.Close();
            Grammar gramatyka = new Grammar(docBiletomat, "rootBiletomat");

            return(gramatyka);
        }
Ejemplo n.º 3
0
        public void CompileStronglyTypedGrammarFromFileToCfg()
        {
            SrgsDocument srgsDoc = CreateSrgsDocument();

            string temp = GetTestFilePath();

            using (XmlWriter writer = XmlWriter.Create(temp))
            {
                srgsDoc.WriteSrgs(writer);
            }

            using var ms = new MemoryStream();

            SrgsGrammarCompiler.Compile(temp, ms);

            Assert.True(ms.Position > 0);
        }
Ejemplo n.º 4
0
        public void CreateMoreElaborateGrammar()
        {
            Choices fruit     = new Choices("oranges", "apples", "bananas");
            Choices vegetable = new Choices("cabbage", "carrots", "spinach");
            Choices misc      = new Choices("chocolate bars", "coke bottles", "cookies");

            string[] quantities = new string[9];
            for (int i = 2; i < 11; ++i)
            {
                quantities[i - 2] = i.ToString();
            }

            Choices quantity = new Choices(quantities);

            GrammarBuilder gb = new GrammarBuilder("I would like");

            gb.Append(new SemanticResultKey("Quantity", quantity));
            gb.Append(new SemanticResultKey("Fruit", fruit));

            GrammarBuilder gb2 = new GrammarBuilder("and");

            gb2.Append(new SemanticResultKey("Quantity", quantity));
            gb2.Append(new SemanticResultKey("Misc", misc));

            gb.Append(new SemanticResultKey("Misc", gb2), 0, 1);
            gb.Append("and some");
            gb.Append(new SemanticResultKey("Vegetable", vegetable));

            SrgsDocument srgsDoc = new SrgsDocument(gb);

            var builder = new StringBuilder();

            using (XmlWriter writer = XmlWriter.Create(builder))
            {
                srgsDoc.WriteSrgs(writer);
            }

            Assert.Contains("oranges", builder.ToString());
        }
Ejemplo n.º 5
0
        public SrgsDocument CreateGrammarDoc_SRGS()
        {
            //reset caches
            caps_rules = new Dictionary<EDeviceCapabilities, SrgsRule>();
            if (currentSrgsDoc == null)
            {

                currentSrgsDoc = new SrgsDocument();

                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
                //Grammar: Holly, [<courtesy>] <action> (<class>|<device>) [<location>] <courtesy>
                // Courtesy: Please, Thank You, Thanks, Cheers
                // Action: capabilities
                // Class: classes
                // Device: device friendly names
                // Location: rooms, here, this

                SrgsOneOf end_courtesy = new SrgsOneOf(new string[] { "please" });
                SrgsOneOf actionItemLocation_choices = new SrgsOneOf();
                foreach (Room rm in ListRooms())
                {
                    if (rm.Name == "") continue;
                    Dictionary<string, SrgsRuleRef> actionsPerDevice = new Dictionary<string, SrgsRuleRef>();
                    foreach (Device d in rm.ListDevices())
                    {
                        SrgsRuleRef caps_ruleref = SrgsActionsFromCapabilities(d.Capabilities, currentSrgsDoc);
                        if (caps_ruleref == null) continue;
                        string cl = SoundsLike.Get(d.Class, false);
                        if (cl != "" && !actionsPerDevice.ContainsKey(cl))
                        {
                            actionsPerDevice.Add(cl, caps_ruleref);
                        }
                        if (d.FriendlyName != "")
                        {
                            if (!actionsPerDevice.ContainsKey(d.FriendlyName))
                                actionsPerDevice.Add(d.FriendlyName, caps_ruleref);
                        }
                    }
                    //actionsperdevice.Value + actionsperdevice.Key+room
                    if (actionsPerDevice.Count == 0) continue; //nothing in the room
                    SrgsOneOf action_items = new SrgsOneOf();
                    bool action_items_valid = false;
                    foreach (string item in actionsPerDevice.Keys)
                    {
                        if (item == "") continue;
                        SrgsRule ai_gb = new SrgsRule(AudioRecog_SAPI.SrgsCleanupID(rm.Name + "_" + item));
                        ai_gb.Add(actionsPerDevice[item]);
                        ai_gb.Add(new SrgsItem(item));
                        currentSrgsDoc.Rules.Add(ai_gb);
                        //SrgsItem ai_gb_item = new SrgsItem(new SrgsRuleRef(ai_gb, "item"));
                        SrgsItem ai_gb_item = new SrgsItem(new SrgsRuleRef(ai_gb));
                        ai_gb_item.Add(new SrgsNameValueTag("item", item));
                        action_items.Add(ai_gb_item);
                        action_items_valid = true;
                    }
                    if (!action_items_valid) continue;
                    SrgsRule ail_gb = new SrgsRule(AudioRecog_SAPI.SrgsCleanupID(rm.Name + "__ail"), action_items);
                    if (rm != CurrentLocation)
                    {
                        //SrgsItem loc1 = new SrgsItem("in the " + rm.Name);
                        SrgsItem loc1 = new SrgsItem(0, 1, "in the " + rm.Name);
                        loc1.Add(new SrgsNameValueTag("room", rm.Name));
                        ail_gb.Add(loc1);
                    }
                    else
                    {
                        SrgsOneOf loc = new SrgsOneOf(new string[] { "in the " + rm.Name, "here" });
                        SrgsItem loc_item = new SrgsItem(0, 1, loc);
                        //SrgsItem loc_item = new SrgsItem(loc);
                        loc_item.Add(new SrgsNameValueTag("room", rm.Name));
                        ail_gb.Add(loc_item);
                    }
                    currentSrgsDoc.Rules.Add(ail_gb);
                    //SrgsItem ail_gb_item = new SrgsItem(new SrgsRuleRef(ail_gb, "room"));
                    SrgsItem ail_gb_item = new SrgsItem(new SrgsRuleRef(ail_gb));
                    //ail_gb_item.Add(new SrgsNameValueTag("room", rm.Name));
                    actionItemLocation_choices.Add(ail_gb_item);
                }
                SrgsRule root_rule = new SrgsRule("rootrule");
                root_rule.Add(new SrgsItem("Holly"));
                root_rule.Add(actionItemLocation_choices);
                root_rule.Add(end_courtesy);
                currentSrgsDoc.Rules.Add(root_rule);
                currentSrgsDoc.Root = root_rule;

                XmlWriter xmlout = XmlWriter.Create(@"C:\Users\ian\Desktop\grammar.xml");
                currentSrgsDoc.WriteSrgs(xmlout);
                xmlout.Close();
            }
            return currentSrgsDoc;
        }
        private Grammar init()
        {
            SrgsRule  ruleOrzeczenie = new SrgsRule("Orzeczenie");
            SrgsOneOf orzeczenie     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(0, 1, "chciałbym"),
                new SrgsItem(0, 1, "daj"),
                new SrgsItem(0, 1, "dawaj"),
                new SrgsItem(0, 1, "podaj"),
                new SrgsItem(0, 1, "poproszę"),
                new SrgsItem(0, 1, "proszę"),
                new SrgsItem(0, 1, "sprzedaj")
            });

            ruleOrzeczenie.Add(orzeczenie);

            SrgsRule  ruleBezokolicznik = new SrgsRule("Bezokolicznik");
            SrgsOneOf bezokolicznik     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(0, 1, "dostać"),
                new SrgsItem(0, 1, "kupić"),
                new SrgsItem(0, 1, "podać"),
                new SrgsItem(0, 1, "wziąć")
            });

            ruleBezokolicznik.Add(bezokolicznik);

            SrgsRule ruleDopelnienie = new SrgsRule("Dopelnienie");
            string   guitarItem      = "gitarę";
            string   drumsItem       = "perkusję";
            string   violinItem      = "skrzypce";
            string   bellsItem       = "dzwoneczki";
            string   bassItem        = "bas";

            productIdGrammarDictionary.Add(1, guitarItem);
            productIdGrammarDictionary.Add(2, drumsItem);
            productIdGrammarDictionary.Add(3, violinItem);
            productIdGrammarDictionary.Add(4, bellsItem);
            productIdGrammarDictionary.Add(5, bassItem);

            SrgsOneOf dopelnienie = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, guitarItem),
                new SrgsItem(1, 1, drumsItem),
                new SrgsItem(1, 1, violinItem),
                new SrgsItem(1, 1, bellsItem),
                new SrgsItem(1, 1, bassItem)
            });

            ruleDopelnienie.Add(dopelnienie);
            SrgsRule rootRule = new SrgsRule("rootBiletomat");

            rootRule.Scope = SrgsRuleScope.Public;
            rootRule.Add(new SrgsRuleRef(ruleOrzeczenie, "ORZECZENIE"));
            rootRule.Add(new SrgsRuleRef(ruleBezokolicznik, "BEZOKOLICZNIK"));
            rootRule.Add(new SrgsRuleRef(ruleDopelnienie, "DOPELNIENIE"));

            SrgsDocument docBiletomat = new SrgsDocument();

            docBiletomat.Culture = pRecognitionLanguage;

            docBiletomat.Rules.Add(new SrgsRule[]
                                   { rootRule, ruleOrzeczenie, ruleBezokolicznik, ruleDopelnienie }
                                   );

            docBiletomat.Root = rootRule;

            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("srgsDocument.xml");
            docBiletomat.WriteSrgs(writer);
            writer.Close();
            return(new Grammar(docBiletomat, "rootBiletomat"));
        }
Ejemplo n.º 7
0
        private void LoadGrammarForEngineAndPlugins()
        {
            var memoryStream = new MemoryStream(Resources.mainDocument);
            var xmlReader = new XmlTextReader(memoryStream);
            var mainDocument = new SrgsDocument(xmlReader);

            //Rule for plugins
            var pluginRules = new SrgsRule("plugin");
            var choices = new SrgsOneOf();
            pluginRules.Add(choices);

            //Main rule (entry point for speech)
            var mainRule = new SrgsRule("main");
            var systemName = new SrgsItem(_config.SpeechRecognitionElement.Name);
            var speakAnything = SrgsRuleRef.Garbage;
            var refPluginRules = new SrgsRuleRef(pluginRules);
            SrgsItem executeCommandRule = null;
            if (!String.IsNullOrWhiteSpace(_config.SpeechRecognitionElement.ExecuteCommandPhrase))
                executeCommandRule = new SrgsItem(_config.SpeechRecognitionElement.ExecuteCommandPhrase);

            //Genere main Rule
            mainRule.Add(systemName);
            mainRule.Add(speakAnything);
            mainRule.Add(refPluginRules);
            mainRule.Add(new SrgsSemanticInterpretationTag("out=rules.plugin;"));
            mainRule.Add(speakAnything);
            if (!String.IsNullOrWhiteSpace(_config.SpeechRecognitionElement.ExecuteCommandPhrase))
                mainRule.Add(executeCommandRule);
            mainRule.Scope = SrgsRuleScope.Private;

            //Here you should add choices to the document per Plugin
            foreach (var plugin in _plugins)
            {
                plugin.AddGrammarRules(mainDocument.Rules, choices);
            }

            mainDocument.Rules.Add(mainRule);
            mainDocument.Rules.Add(pluginRules);
            mainDocument.Root = mainRule;
            mainDocument.Culture = _speechRecognitionEngine.RecognizerInfo.Culture;
            mainDocument.Mode = SrgsGrammarMode.Voice;
            mainDocument.PhoneticAlphabet = SrgsPhoneticAlphabet.Sapi;

            using (var textWriter = new StringWriter())
            {
                using (var xmlWriter = new XmlTextWriter(textWriter))
                {
                    mainDocument.WriteSrgs(xmlWriter);
                    _log.Info(String.Format("Grammar for the recognition engine in the culture {0}, is {1}", _speechRecognitionEngine.RecognizerInfo.Culture.TwoLetterISOLanguageName, textWriter));
                }
            }

            _speechRecognitionEngine.LoadGrammar(new Grammar(mainDocument));
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            // Create the "Subject" rule.
            SrgsRule  subjRule = new SrgsRule("id_Subject");
            SrgsOneOf subjList = new SrgsOneOf(new string[] { "I", "you", "he", "she", "Tom", "Mary" });

            subjRule.Add(subjList);

            // Create the "Verb" rule.
            SrgsRule  verbRule = new SrgsRule("id_Verb");
            SrgsOneOf verbList = new SrgsOneOf(new string[] { "ate", "bought", "saw", "sold", "wanted" });

            verbRule.Add(verbList);

            // Create the "Object" rule.
            SrgsRule  objRule = new SrgsRule("id_Object");
            SrgsOneOf objList = new SrgsOneOf(new string[] { "apple", "banana", "pear", "peach", "melon" });

            objRule.Add(objList);

            // Create the root rule.
            // In this grammar, the root rule contains references to the other three rules.
            SrgsRule rootRule = new SrgsRule("Subj_Verb_Obj");

            rootRule.Scope = SrgsRuleScope.Public;

            // Create the "Subject" and "Verb" rule references and add them to the SrgsDocument.
            SrgsRuleRef subjRef = new SrgsRuleRef(subjRule, "theSubject");

            rootRule.Add(subjRef);

            SrgsRuleRef verbRef = new SrgsRuleRef(verbRule, "theVerb");

            rootRule.Add(verbRef);

            // Add logic to handle articles: "the", "a", "and", occurring zero or one time.
            SrgsOneOf articles = new SrgsOneOf(
                new SrgsItem[] { new SrgsItem(0, 1, "the"), new SrgsItem(0, 1, "a"), new SrgsItem(0, 1, "an") }
                );

            rootRule.Add(articles);

            // Create the "Object" rule reference and add it to the SrgsDocument.
            SrgsRuleRef objRef = new SrgsRuleRef(objRule, "theObject");

            rootRule.Add(objRef);

            // Create an SrgsDocument object that contains all four rules.
            SrgsDocument document = new SrgsDocument();

            document.Rules.Add(rootRule, subjRule, verbRule, objRule);

            // Set "rootRule" as the root rule of the grammar.
            document.Root = rootRule;

            // Create a Grammar object, initializing it with the root rule.
            Grammar g = new Grammar(document, rootRule.Id);

            // Create a new SpeechRecognizer instance.
            SpeechRecognizer sr = new SpeechRecognizer();

            // Load the Grammar object into the recognizer.
            sr.LoadGrammar(g);

            // Produce an XML file that contains the grammar.
            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("srgsDocument.xml");
            document.WriteSrgs(writer);
            writer.Close();

            sr.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(sr_SpeechRecognized);
            while (true)
            {
                Console.Read();
            }
        }
Ejemplo n.º 9
0
        private Grammar init()
        {
            SrgsRule  ruleCity = new SrgsRule("Miasto");
            SrgsOneOf city     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, "Warszawa"),
                new SrgsItem(1, 1, "Radom"),
                new SrgsItem(1, 1, "Gdańsk"),
                new SrgsItem(1, 1, "Kielce"),
                new SrgsItem(1, 1, "Poznań")
            });

            ruleCity.Add(city);

            SrgsRule  ruleStreet = new SrgsRule("Ulica");
            SrgsOneOf street     = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem(1, 1, "ulica Biała"),
                new SrgsItem(1, 1, "ulica Jasna"),
                new SrgsItem(1, 1, "ulica Ciemna"),
                new SrgsItem(1, 1, "ulica Czarna"),
                new SrgsItem(1, 1, "ulica Szybka"),
                new SrgsItem(1, 1, "ulica Wolna")
            });

            ruleStreet.Add(street);

            SrgsRule  ruleLiczba = new SrgsRule("Liczebnik");
            SrgsOneOf liczebnik  = new SrgsOneOf(new SrgsItem[]
            {
                new SrgsItem("1"),
                new SrgsItem("2"),
                new SrgsItem("3"),
                new SrgsItem("4"),
                new SrgsItem("5"),
                new SrgsItem("6"),
                new SrgsItem("7"),
                new SrgsItem("8"),
                new SrgsItem("9")
            });

            ruleLiczba.Add(liczebnik);

            SrgsRule rootRule = new SrgsRule("rootBiletomat");

            rootRule.Scope = SrgsRuleScope.Public;

            rootRule.Add(new SrgsRuleRef(ruleCity, "IMIE"));
            rootRule.Add(new SrgsRuleRef(ruleStreet, "NAZWISKO"));
            rootRule.Add(new SrgsRuleRef(ruleLiczba, "LICZBA"));


            SrgsDocument docBiletomat = new SrgsDocument();

            docBiletomat.Culture = pRecognitionLanguage;
            docBiletomat.Rules.Add(new SrgsRule[]
                                   { rootRule, ruleCity, ruleStreet, ruleLiczba }
                                   );
            docBiletomat.Root = rootRule;
            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create("srgsDocument.xml");
            docBiletomat.WriteSrgs(writer);
            writer.Close();
            Grammar gramatyka = new Grammar(docBiletomat, "rootBiletomat");

            return(gramatyka);
        }
Ejemplo n.º 10
0
        public static SrgsDocument BuildSrgsGrammar()
        {
            SrgsDocument document = new SrgsDocument();

            // make a new subject item and then add all of it's rules to the document
            subjectObject = new Subject();
            foreach(SrgsRule rule in subjectObject.RuleList)
            {
                document.Rules.Add(rule);
            }

            SrgsRuleRef subjectRef = new SrgsRuleRef(subjectObject.RootRule);

            // go through and add all of the commands
            commandObjects = new Dictionary<string, Command>();
            SrgsOneOf commandSet = new SrgsOneOf();

            // add just the subjects
            SrgsItem select = new SrgsItem();
            select.Add(new SrgsItem(subjectRef));
            select.Add(new SrgsSemanticInterpretationTag("out.subject=rules.subject;"));
            commandSet.Add(select);

            #region Commands
            #region Move (1)
            // return to formation (1)
            Command returnToFormation = new Command("FORMUP", new string[] { "return to formation", "form up" }, new ushort[] { Keys.One, Keys.One }, subjectRef);
            commandObjects.Add("FORMUP", returnToFormation);
            commandSet.Add(returnToFormation.Item);

            // advance (2)
            Command advance = new Command("ADVANCE", new string[] { "advance", "move up" }, new ushort[] { Keys.One, Keys.Two }, subjectRef);
            commandObjects.Add("ADVANCE", advance);
            commandSet.Add(advance.Item);

            // stay back (3)
            Command stayBack = new Command("STAYBACK", new string[] { "stay back" }, new ushort[] { Keys.One, Keys.Three }, subjectRef);
            commandObjects.Add("STAYBACK", stayBack);
            commandSet.Add(stayBack.Item);

            // flank left (4)
            Command flankLeft = new Command("FLANKLEFT", new string[] { "flank left" }, new ushort[] { Keys.One, Keys.Four }, subjectRef);
            commandObjects.Add("FLANKLEFT", flankLeft);
            commandSet.Add(flankLeft.Item);

            // flank right (5)
            Command flankRight = new Command("FLANKRIGHT", new string[] { "flank right" }, new ushort[] { Keys.One, Keys.Five }, subjectRef);
            commandObjects.Add("FLANKRIGHT", flankRight);
            commandSet.Add(flankRight.Item);

            // stop (6)
            Command stop = new Command("STOP", new string[] { "stop", "hold position" }, new ushort[] { Keys.One, Keys.Six }, subjectRef);
            commandObjects.Add("STOP", stop);
            commandSet.Add(stop.Item);

            // Wait for me (7)
            Command waitForMe = new Command("WAIT", new string[] { "wait for me", "wait up" }, new ushort[] { Keys.One, Keys.Seven }, subjectRef);
            commandObjects.Add("WAIT", waitForMe);
            commandSet.Add(waitForMe.Item);

            // Find cover (8)
            Command cover = new Command("COVER", new string[] { "go for cover", "look for cover", "cover", "find cover" }, new ushort[] { Keys.One, Keys.Eight }, subjectRef);
            commandObjects.Add("COVER", cover);
            commandSet.Add(cover.Item);

            // Find cover (9)
            Command nextWaypoint = new Command("NEXTWAYPOINT", new string[] { "next waypoint", "go to the next waypoint" }, new ushort[] { Keys.One, Keys.Nine }, subjectRef);
            commandObjects.Add("NEXTWAYPOINT", nextWaypoint);
            commandSet.Add(nextWaypoint.Item);
            #endregion

            #region Target (2)
            // open menu
            Command openTargetMenu = new Command("OPENTARGET", new string[] { "show targets", "target menu" }, new ushort[] { Keys.Two }, subjectRef);
            commandObjects.Add("OPENTARGET", openTargetMenu);
            commandSet.Add(openTargetMenu.Item);

            // cancel target (1)
            Command cancelTarget = new Command("CANCELTARGET", new string[] { "cancel targets", "no target" }, new ushort[] { Keys.Two, Keys.One }, subjectRef);
            commandObjects.Add("CANCELTARGET", cancelTarget);
            commandSet.Add(cancelTarget.Item);
            #endregion

            #region Engage (3)
            // open fire (1)
            Command openFire = new Command("OPENFIRE", new string[] { "open fire", "go loud", "fire at will" }, new ushort[] { Keys.Three, Keys.One }, subjectRef);
            commandObjects.Add("OPENFIRE", openFire);
            commandSet.Add(openFire.Item);

            // hold fire (2)
            Command holdFire = new Command("HOLDFIRE", new string[] { "hold fire", "go quiet" }, new ushort[] { Keys.Three, Keys.Two }, subjectRef);
            commandObjects.Add("HOLDFIRE", holdFire);
            commandSet.Add(holdFire.Item);

            // fire (3)
            Command fire = new Command("FIRE", new string[] { "fire", "take the shot" }, new ushort[] { Keys.Three, Keys.Three }, subjectRef);
            commandObjects.Add("FIRE", fire);
            commandSet.Add(fire.Item);

            // engage (4)
            Command engage = new Command("ENGAGE", new string[] { "engage" }, new ushort[] { Keys.Three, Keys.Four }, subjectRef);
            commandObjects.Add("ENGAGE", engage);
            commandSet.Add(engage.Item);

            // engage at will (5)
            Command enageAtWill = new Command("ENGAGEATWILL", new string[] { "engage at will" }, new ushort[] { Keys.Three, Keys.Five }, subjectRef);
            commandObjects.Add("ENGAGEATWILL", enageAtWill);
            commandSet.Add(enageAtWill.Item);

            // disengage (6)
            Command disengage = new Command("DISENGAGE", new string[] { "disengage" }, new ushort[] { Keys.Three, Keys.Six }, subjectRef);
            commandObjects.Add("DISENGAGE", disengage);
            commandSet.Add(disengage.Item);

            // scan horizon (7)
            Command scanHorizon = new Command("SCANHORIZON", new string[] { "scan horizon", "scan the horizon" }, new ushort[] { Keys.Three, Keys.Seven }, subjectRef);
            commandObjects.Add("SCANHORIZON", scanHorizon);
            commandSet.Add(scanHorizon.Item);

            // watch direction (8)
            // team direct object
            DirectObject direction = new DirectObject("directionDO");
            direction.Add(new string[] { "north" }, "NORTH", new ushort[] { Keys.One });
            direction.Add(new string[] { "north east" }, "NORTHEAST", new ushort[] { Keys.Two });
            direction.Add(new string[] { "east" }, "EAST", new ushort[] { Keys.Three });
            direction.Add(new string[] { "south east" }, "SOUTHEAST", new ushort[] { Keys.Four });
            direction.Add(new string[] { "south" }, "SOUTH", new ushort[] { Keys.Five });
            direction.Add(new string[] { "south west" }, "SOUTHWEST", new ushort[] { Keys.Six });
            direction.Add(new string[] { "west" }, "WEST", new ushort[] { Keys.Seven });
            direction.Add(new string[] { "north west" }, "NORTHWEST", new ushort[] { Keys.Eight });

            foreach (SrgsRule rule in direction.RuleList)
            {
                document.Rules.Add(rule);
            }

            Command watch = new Command("WATCH", new string[] { "watch" }, new ushort[] { Keys.Three, Keys.Eight }, subjectRef, direction);
            commandObjects.Add("WATCH", watch);
            commandSet.Add(watch.Item);

            // suppressive fire (9)
            Command suppresiveFire = new Command("SUPRESS", new string[] { "supppresive fire" }, new ushort[] { Keys.Three, Keys.Nine }, subjectRef);
            commandObjects.Add("SUPRESS", suppresiveFire);
            commandSet.Add(suppresiveFire.Item);
            #endregion

            #region Mount (4)
            // open mount menu
            Command openMountMenu = new Command("OPENMOUNT", new string[] { "show vehicles", "mount menu", "get in vehicle" }, new ushort[] { Keys.Four }, subjectRef);
            commandObjects.Add("OPENMOUNT", openMountMenu);
            commandSet.Add(openMountMenu.Item);

            // dismount (1)
            Command dismount = new Command("DISMOUNT", new string[] { "dismount", "get out" }, new ushort[] { Keys.Four, Keys.One }, subjectRef);
            commandObjects.Add("DISMOUNT", dismount);
            commandSet.Add(dismount.Item);
            #endregion

            #region Action (6)
            // open menu
            Command openActionMenu = new Command("OPENACTION", new string[] { "show actions", "action menu", "perform action" }, new ushort[] { Keys.Six }, subjectRef);
            commandObjects.Add("OPENACTION", openActionMenu);
            commandSet.Add(openActionMenu.Item);
            #endregion

            #region Combat Mode (7)
            // stealth (1)
            Command stealth = new Command("STEALTH", new string[] { "stealth", "stealthy", "stealth mode"}, new ushort[] { Keys.Seven, Keys.One }, subjectRef);
            commandObjects.Add("STEALTH", stealth);
            commandSet.Add(stealth.Item);

            // combat (2)
            Command combat = new Command("COMBAT", new string[] { "combat", "danger", "combat mode" }, new ushort[] { Keys.Seven, Keys.Two }, subjectRef);
            commandObjects.Add("COMBAT", combat);
            commandSet.Add(combat.Item);

            // aware (3)
            Command aware = new Command("AWARE", new string[] { "aware", "aware mode", "stay sharp", "stay frosty" }, new ushort[] { Keys.Seven, Keys.Three }, subjectRef);
            commandObjects.Add("AWARE", aware);
            commandSet.Add(aware.Item);

            // relax (4)
            Command relax = new Command("RELAX", new string[] { "relax", "relaxed mode" }, new ushort[] { Keys.Seven, Keys.Four }, subjectRef);
            commandObjects.Add("RELAX", relax);
            commandSet.Add(relax.Item);

            // stand up (6)
            Command standUp = new Command("STANDUP", new string[] { "stand up", "get up" }, new ushort[] { Keys.Seven, Keys.Six }, subjectRef);
            commandObjects.Add("STANDUP", standUp);
            commandSet.Add(standUp.Item);

            // stay crouched (7)
            Command stayCrouched = new Command("CROUCH", new string[] { "get low", "crouch", "stay crouched", "stay low" }, new ushort[] { Keys.Seven, Keys.Seven }, subjectRef);
            commandObjects.Add("CROUCH", stayCrouched);
            commandSet.Add(stayCrouched.Item);

            // go prone (8)
            Command goProne = new Command("PRONE", new string[] { "go prone", "get down", "prone", "hit the dirt" }, new ushort[] { Keys.Seven, Keys.Eight }, subjectRef);
            commandObjects.Add("PRONE", goProne);
            commandSet.Add(goProne.Item);

            // copy my stance (9)
            Command copyMyStance = new Command("COPYMYSTANCE", new string[] { "copy my stance", "default stance" }, new ushort[] { Keys.Seven, Keys.Nine }, subjectRef);
            commandObjects.Add("COPYMYSTANCE", copyMyStance);
            commandSet.Add(copyMyStance.Item);
            #endregion

            #region Formation (8)
            // column (1)
            Command column = new Command("COLUMN", new string[] { "formation column", "form column", "column" }, new ushort[] { Keys.Eight, Keys.One }, subjectRef);
            commandObjects.Add("COLUMN", column);
            commandSet.Add(column.Item);

            // staggered column (2)
            Command staggeredColumn = new Command("STAGGEREDCOLUMN", new string[] { "formation staggered column", "form staggered column", "staggered column" }, new ushort[] { Keys.Eight, Keys.Two }, subjectRef);
            commandObjects.Add("STAGGEREDCOLUMN", staggeredColumn);
            commandSet.Add(staggeredColumn.Item);

            // wedge (3)
            Command wedge = new Command("WEDGE", new string[] { "formation wedge", "form wedge", "wedge" }, new ushort[] { Keys.Eight, Keys.Three }, subjectRef);
            commandObjects.Add("WEDGE", wedge);
            commandSet.Add(wedge.Item);

            // echelon left (4)
            Command echelonLeft = new Command("ECHELONLEFT", new string[] { "formation echelon left", "form echelon left", "echelon left" }, new ushort[] { Keys.Eight, Keys.Four }, subjectRef);
            commandObjects.Add("ECHELONLEFT", echelonLeft);
            commandSet.Add(echelonLeft.Item);

            // echelon right (5)
            Command echeloneRight = new Command("ECHELONRIGHT", new string[] { "formation echelon right", "form echelon right", "echelon right" }, new ushort[] { Keys.Eight, Keys.Five }, subjectRef);
            commandObjects.Add("ECHELONRIGHT", echeloneRight);
            commandSet.Add(echeloneRight.Item);

            // vee (6)
            Command vee = new Command("VEE", new string[] { "formation vee", "form vee", "vee" }, new ushort[] { Keys.Eight, Keys.Six }, subjectRef);
            commandObjects.Add("VEE", vee);
            commandSet.Add(vee.Item);

            // line (7)
            Command line = new Command("LINE", new string[] { "formation line", "form line", "line" }, new ushort[] { Keys.Eight, Keys.Seven }, subjectRef);
            commandObjects.Add("LINE", line);
            commandSet.Add(line.Item);

            // file (8)
            Command file = new Command("FILE", new string[] { "formation file", "form file", "file" }, new ushort[] { Keys.Eight, Keys.Eight }, subjectRef);
            commandObjects.Add("FILE", file);
            commandSet.Add(file.Item);

            // diamond (9)
            Command diamond = new Command("DIAMOND", new string[] { "formation diamond", "form diamond", "diamond" }, new ushort[] { Keys.Eight, Keys.Nine }, subjectRef);
            commandObjects.Add("DIAMOND", diamond);
            commandSet.Add(diamond.Item);
            #endregion

            #region Assign Team (9)
            // team direct object
            DirectObject team = new DirectObject("teamDO");
            team.Add(new string[] { "team red", "red" }, "RED", new ushort[] { Keys.One });
            team.Add(new string[] { "team green", "green" }, "GREEN", new ushort[] { Keys.Two });
            team.Add(new string[] { "team blue", "blue" }, "BLUE", new ushort[] { Keys.Three });
            team.Add(new string[] { "team yellow", "yellow" }, "YELLOW", new ushort[] { Keys.Four });
            team.Add(new string[] { "team white", "white" }, "WHITE", new ushort[] { Keys.Five });

            foreach (SrgsRule rule in team.RuleList)
            {
                document.Rules.Add(rule);
            }

            Command assignTeam = new Command("ASSIGN", new string[] { "assign team", "assign", "add to" }, new ushort[] { Keys.Nine }, subjectRef, team);
            commandObjects.Add("ASSIGN", assignTeam);
            commandSet.Add(assignTeam.Item);
            #endregion

            // not implemented
            #region WW_AiMenu
            #region Infantry Commands (1)
            // heal up (1)

            // rearm (2)

            // inventory (3)

            // fire on my lead (4)

            // garrison building (5)

            // clear building (6)

            // follow target (7)
            #endregion

            #region WayPoints (4)
            // set waypoints (1)

            // add waypoints (2)

            // move waypoints (3)

            // delete waypoints (4)

            // wait on waypoint (5)

            // cycle waypoint (6)
            #endregion
            #endregion
            #endregion

            // set the root rule to
            SrgsRule commands = new SrgsRule("commands");
            commands.Add(commandSet);

            document.Rules.Add(commands);
            document.Root = commands;

            // write grammar out for debugging purposes
            System.Xml.XmlWriter xWriter = System.Xml.XmlWriter.Create("grammar.xml");
            document.WriteSrgs(xWriter);
            xWriter.Close();

            return document;
        }
Ejemplo n.º 11
0
        private void Form2_Load(object sender, EventArgs e)
        {
            recEngine = new SpeechRecognitionEngine();

            /*Reglas para Select*/
            SrgsRule  selectRule = new SrgsRule("selectRule");
            SrgsOneOf selectList = new SrgsOneOf(new string[] {
                "selecciona",
                "traeme",
                "busca",
                "obten",
                "muestrame",
                "muestra",
                "imprime",
                "imprimir"
            });

            selectRule.Add(selectList);

            /*Reglas para numero de registros
             * todos, los = all *
             */
            SrgsRule  allRule = new SrgsRule("allRule");
            SrgsOneOf allList = new SrgsOneOf(new string[] {
                "los",
                "todos los"
            });

            allRule.Add(allList);

            /*nombre de la tabla*/
            SrgsRule  tablaRule = new SrgsRule("tablaRule");
            SrgsOneOf tablaList = new SrgsOneOf(new string[] {
                "empleados"
            });

            tablaRule.Add(tablaList);
            SrgsRule  whereRule = new SrgsRule("whereRule");
            SrgsOneOf whereList = new SrgsOneOf(new string[] {
                "igual"
            });

            allRule.Add(allList);


            /*La referencia con una root ruke hace que que las reglas se unana y tengan que tener un
             * orden especifico, quitar o comentar la regla principal y quirar del la creacion del documenteo */
            /*Regla principal*/
            SrgsRule mainRule = new SrgsRule("mainRule");

            mainRule.Scope = SrgsRuleScope.Public;

            /*Unir los select con los all*/
            // Create the "Subject" and "Verb" rule references and add them to the SrgsDocument.
            SrgsRuleRef selectRef = new SrgsRuleRef(selectRule, "theSelect");

            mainRule.Add(selectRef);

            SrgsRuleRef allRef = new SrgsRuleRef(allRule, "theAll");

            mainRule.Add(allRef);

            SrgsRuleRef tablaRef = new SrgsRuleRef(tablaRule, "theTabla");

            mainRule.Add(tablaRef);

            //Creando el documento con las reglas
            SrgsDocument newDocumento = new SrgsDocument();

            newDocumento.Rules.Add(new SrgsRule[] {
                mainRule,
                selectRule,
                allRule,
                tablaRule
            });
            newDocumento.Root = mainRule;

            //Agragar gramatica al engine
            Grammar grammar = new Grammar(newDocumento, "mainRule");

            recEngine.LoadGrammar(grammar);

            //Crear XML
            System.Xml.XmlWriter writer =
                System.Xml.XmlWriter.Create("C:\\Users\\Misael\\Documents\\ejemplo.xml");
            newDocumento.WriteSrgs(writer);
            writer.Close();


            // Attach a handler for the SpeechRecognized event.
            recEngine.SpeechRecognized +=
                new EventHandler <SpeechRecognizedEventArgs>(recEngine_SpeechRecognized);

            // Configure the input to the SpeechRecognitionEngine object.
            recEngine.SetInputToDefaultAudioDevice();

            // Start asynchronous recognition.
            recEngine.RecognizeAsync();
        }
Ejemplo n.º 12
0
        public System.Speech.Recognition.SrgsGrammar.SrgsDocument CreateGrammarDoc_SRGS()
        {
            if (currentSrgsDoc != null) return currentSrgsDoc;

            SrgsDocument doc = new SrgsDocument();
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
            SrgsOneOf ops = new SrgsOneOf();

            //TV Shows
            SrgsOneOf shows = new SrgsOneOf();
            if (mTVShows == null)
            {
                mTVShows = ListTVShows();
            }
            if (mTVShows == null) return null;
            foreach (XBMCProto.TVShow s in mTVShows)
            {
                string temps = CleanString(s.label);
                temps = temps.Trim();
                if (temps == "" || s.tvshowid < 1) continue;
                SrgsItem showitem = new SrgsItem(temps);
                showitem.Add(new SrgsNameValueTag("tvshowid", s.tvshowid));
                shows.Add(showitem);
            }

            SrgsItem cmd_play = new SrgsItem("play show");
            cmd_play.Add(new SrgsNameValueTag("command", "play show"));
            SrgsItem cmd_resume = new SrgsItem("resume show");
            cmd_resume.Add(new SrgsNameValueTag("command", "resume show"));
            SrgsOneOf cmd_tv = new SrgsOneOf(cmd_play, cmd_resume);

            SrgsRule rule_playshow_episode = new SrgsRule("playshow_episode");
            rule_playshow_episode.Add(cmd_tv);
            rule_playshow_episode.Add(shows);
            rule_playshow_episode.Add(new SrgsItem("season"));
            rule_playshow_episode.Add(CreateNumberSRGS("seasonval", doc));  //episode number
            rule_playshow_episode.Add(new SrgsItem("episode"));
            rule_playshow_episode.Add(CreateNumberSRGS("episodeval", doc));   //episode number
            doc.Rules.Add(rule_playshow_episode);
            ops.Add(new SrgsItem(new SrgsRuleRef(rule_playshow_episode)));

            //Movies
            SrgsOneOf films = new SrgsOneOf();
            if (mMovies == null)
            {
                mMovies = ListMovies();
            }
            if (mMovies == null) return null;
            foreach (XBMCProto.Movie m in mMovies)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.movieid < 1) continue;
                SrgsItem filmItem = new SrgsItem(temps);
                filmItem.Add(new SrgsNameValueTag("movieid", m.movieid));
                films.Add(filmItem);
            }

            SrgsItem cmd_play_movie = new SrgsItem("play movie");
            cmd_play_movie.Add(new SrgsNameValueTag("command", "play movie"));
            SrgsItem cmd_resume_movie = new SrgsItem("resume movie");
            cmd_resume_movie.Add(new SrgsNameValueTag("command", "resume movie"));
            SrgsOneOf cmd_movie = new SrgsOneOf(cmd_play_movie, cmd_resume_movie);

            SrgsRule rule_playmovie = new SrgsRule("playmovie");
            rule_playmovie.Add(cmd_movie);
            rule_playmovie.Add(films);
            doc.Rules.Add(rule_playmovie);
            ops.Add(new SrgsItem(new SrgsRuleRef(rule_playmovie)));

            //Music Genres
            SrgsOneOf audioGenres = new SrgsOneOf();
            if (mGenres == null)
            {
                mGenres = ListAudioGenres();
            }
            if (mGenres == null) return null;
            foreach (XBMCProto.Genre m in mGenres)
            {
                string temps = CleanString(m.label);
                temps = temps.Trim();
                if (temps == "" || m.genreid < 1) continue;
                SrgsItem agItem = new SrgsItem(temps+" music");
                agItem.Add(new SrgsNameValueTag("genreid", m.genreid));
                audioGenres.Add(agItem);
            }

            SrgsItem cmd_play_genre = new SrgsItem("play me some");
            cmd_play_genre.Add(new SrgsNameValueTag("command", "play me some"));
            SrgsOneOf cmd_genre = new SrgsOneOf(cmd_play_genre);

            SrgsRule rule_playgenre = new SrgsRule("playgenre");
            rule_playgenre.Add(cmd_genre);
            rule_playgenre.Add(audioGenres);
            doc.Rules.Add(rule_playgenre);
            ops.Add(new SrgsItem(new SrgsRuleRef(rule_playgenre)));

            //Other
            SrgsItem cmd_stop_media = new SrgsItem("stop media");
            cmd_stop_media.Add(new SrgsNameValueTag("command", "stop media"));
            SrgsItem cmd_pause_media = new SrgsItem("pause media");
            cmd_pause_media.Add(new SrgsNameValueTag("command", "pause media"));
            SrgsItem cmd_resume_media = new SrgsItem("resume media");
            cmd_resume_media.Add(new SrgsNameValueTag("command", "resume media"));
            ops.Add(new SrgsItem(cmd_stop_media));
            ops.Add(new SrgsItem(cmd_resume_media));
            ops.Add(new SrgsItem(cmd_pause_media));

            SrgsRule root_rule = new SrgsRule("rootrule");
            root_rule.Add(new SrgsItem("Holly"));
            root_rule.Add(ops);
            root_rule.Add(new SrgsItem("please"));
            doc.Rules.Add(root_rule);

            doc.Root = root_rule;

            XmlWriter xmlout = XmlWriter.Create(@"C:\Users\ian\Desktop\xbmc-grammar.xml");
            doc.WriteSrgs(xmlout);
            xmlout.Close();

            currentSrgsDoc = doc;
            return currentSrgsDoc;
        }