Ejemplo n.º 1
0
        //Add item in the grammar and reload it
        public void addItemInGrammarAndReloadEngine(string nameOfRule, int idOfBalise, string itemToAdd)
        {
            #region Choose the grammar according to the language system
            String stringCurrentCulture = Thread.CurrentThread.CurrentCulture.Name;
            String nameOfGrammarLoaded  = "";

            if (stringCurrentCulture == "fr-FR")
            {
                nameOfGrammarLoaded = "Grammar/GrammarIterumFR.grxml";
            }
            else if (stringCurrentCulture == "en-US")
            {
                nameOfGrammarLoaded = "Grammar/GrammarIterumEN.grxml";
            }
            else
            {
                nameOfGrammarLoaded = "Grammar/GrammarIterumFR.grxml";
            }
            #endregion

            #region Add a item in the grammar and reload it
            SrgsDocument xmlGrammar = new SrgsDocument(nameOfGrammarLoaded); //Creation of file in the norme SRGS from the grammar file in format grxml

            addItemInABalise(xmlGrammar, nameOfRule, idOfBalise, itemToAdd); //Method to add item dynamically in the grammar

            Grammar grammar = new Grammar(xmlGrammar);                       //Creation of grammar from the the grammar file in format grxml
            m_ASREngine.LoadGrammar(grammar);                                //Load grammar
            #endregion
        }
        private Grammar GetGrammar()
        {
            SrgsDocument document = new SrgsDocument();

            SrgsRule rootRule = new SrgsRule("directionRule");

            rootRule.Scope = SrgsRuleScope.Public;

            List <SrgsRule> oneTickGrammarDocument                    = GetDirectionRule(firstNumberEntry, "Tick", directionEntries, "oneTickRule");
            List <SrgsRule> multipleTicksGrammarDocument              = GetDirectionRule(numberEntries, "Ticks", directionEntries, "multipleTicksRule");
            List <SrgsRule> oneTickNoBindingWordGrammarDocument       = GetDirectionRule(firstNumberEntry, null, directionEntries, "oneTickRuleNoBindingWord");
            List <SrgsRule> multipleTicksNoBindingWordGrammarDocument = GetDirectionRule(numberEntries, null, directionEntries, "multipleTicksRuleNoBindingWord");

            SrgsOneOf oneOfElements = new SrgsOneOf(
                new SrgsItem(new SrgsRuleRef(oneTickGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(multipleTicksGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(oneTickNoBindingWordGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(multipleTicksNoBindingWordGrammarDocument[0]))
                );

            rootRule.Add(oneOfElements);

            document.Rules.Add(rootRule);
            document.Rules.Add(oneTickGrammarDocument.ToArray());
            document.Rules.Add(multipleTicksGrammarDocument.ToArray());
            document.Rules.Add(oneTickNoBindingWordGrammarDocument.ToArray());
            document.Rules.Add(multipleTicksNoBindingWordGrammarDocument.ToArray());

            document.Root = rootRule;

            return(new Grammar(document));
        }
Ejemplo n.º 3
0
 private static MemoryStream CombineCfg(string rule, Stream stream, SrgsRule[] extraRules)
 {
     using (MemoryStream memoryStream = new MemoryStream())
     {
         SrgsDocument srgsDocument = new SrgsDocument();
         srgsDocument.TagFormat = SrgsTagFormat.KeyValuePairs;
         foreach (SrgsRule srgsRule in extraRules)
         {
             srgsDocument.Rules.Add(srgsRule);
         }
         SrgsGrammarCompiler.Compile(srgsDocument, memoryStream);
         using (StreamMarshaler streamHelper = new StreamMarshaler(stream))
         {
             long    position = stream.Position;
             Backend org      = new Backend(streamHelper);
             stream.Position       = position;
             memoryStream.Position = 0L;
             MemoryStream memoryStream2 = new MemoryStream();
             using (StreamMarshaler streamHelper2 = new StreamMarshaler(memoryStream))
             {
                 Backend extra   = new Backend(streamHelper2);
                 Backend backend = Backend.CombineGrammar(rule, org, extra);
                 using (StreamMarshaler streamBuffer = new StreamMarshaler(memoryStream2))
                 {
                     backend.Commit(streamBuffer);
                     memoryStream2.Position = 0L;
                     return(memoryStream2);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Probuje zwalidować garmatykę, dodaje atrybuty takie jak xml:lang lub zmienia namespace by był dobrze rozumiany przez ASR
        /// </summary>
        /// <param name="xmlGrammar">zawartość xmla z gramatyką</param>
        /// <returns>Czy wyjściowy xml jest poprawny</returns>
        public static bool ValidateAndFixGrammar(ref string xmlGrammar)
        {
            var node    = System.Xml.Linq.XElement.Parse(xmlGrammar);
            var culture = ConfigurationManager.AppSettings["defaultCulture"];

            if (node.Attribute(System.Xml.Linq.XNamespace.Xml + "lang") == null)
            {
                xmlGrammar = xmlGrammar.Replace("<grammar", $"<grammar xml:lang=\"{culture}\"");
            }
            if (string.IsNullOrEmpty(node.Name.Namespace.ToString()))
            {
                xmlGrammar = xmlGrammar.Replace("<grammar", "<grammar xmlns=\"http://www.w3.org/2001/06/grammar\" ");
            }
            else
            {
                xmlGrammar = Regex.Replace(xmlGrammar, "xmlns=\".*?\"", "xmlns=\"http://www.w3.org/2001/06/grammar\" ");
            }
            if (node.Attribute("version") == null)
            {
                xmlGrammar = xmlGrammar.Replace("<grammar", "<grammar version=\"1.0\" ");
            }
            using (var reader = System.Xml.XmlReader.Create(new StringReader(xmlGrammar)))
            {
                try
                {
                    var srgs = new SrgsDocument(reader);
                }
                catch (Exception e)
                {
                    return(false);
                }
                return(true);
            }
        }
Ejemplo n.º 5
0
        public Grammar[] CreateGrammar_Basic2DX()
        {
            List <Grammar>        grammars = new List <Grammar>();
            List <List <string> > words    = new List <List <string> >();

            int count = phonems_basic.Length;

            for (int i = 0; i < count; i++)
            {
                SrgsDocument doc = new SrgsDocument();
                doc.PhoneticAlphabet = SrgsPhoneticAlphabet.Ups;
                SrgsRule  rule  = new SrgsRule("basic2D" + i);
                SrgsOneOf oneOf = new SrgsOneOf();

                for (int i2 = 0; i2 < count; i2++)
                {
                    string text          = phonems_basic[i] + phonems_basic[i2];
                    string pronunciation = phonems_basic[i] + " " + phonems_basic[i2];

                    SrgsToken token = new SrgsToken(text);
                    token.Pronunciation = pronunciation;
                    SrgsItem item = new SrgsItem(token);
                    oneOf.Add(item);
                }

                rule.Add(oneOf);
                doc.Rules.Add(rule);
                doc.Root    = rule;
                doc.Culture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
                Grammar grammar = new Grammar(doc);
                grammars.Add(grammar);
            }

            return(grammars.ToArray());
        }
Ejemplo n.º 6
0
        public override SpeechRecognitionResult RecognizeFromWav(String filename)
        {
            var engine = null as SpeechRecognitionEngine;

            if (String.IsNullOrWhiteSpace(this.Recognition.Culture) == true)
            {
                engine = new SpeechRecognitionEngine();
            }
            else
            {
                engine = new SpeechRecognitionEngine(CultureInfo.CreateSpecificCulture(this.Recognition.Culture));
            }

            using (engine)
            {
                foreach (var grammar in this.Recognition.Grammars)
                {
                    var doc = new SrgsDocument(Path.Combine(HttpRuntime.AppDomainAppPath, grammar));
                    engine.LoadGrammar(new Grammar(doc));
                }

                if (this.Recognition.Choices.Any() == true)
                {
                    var choices = new Choices(this.Recognition.Choices.ToArray());
                    engine.LoadGrammar(new Grammar(choices));
                }

                engine.SetInputToWaveFile(filename);

                var result = engine.Recognize();

                return((result != null) ? new SpeechRecognitionResult(result.Text, result.Alternates.Select(x => x.Text).ToArray()) : null);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create Grammars for the contact names of customer's contact list
        /// </summary>
        private void Code_PrepareGrammar(object sender, EventArgs e)
        {
            SrgsOneOf oneOf = new SrgsOneOf();

            foreach (var contact in contacts)
            {
                SrgsItem item = new SrgsItem(contact.Value.DisplayName);

                SrgsSemanticInterpretationTag tag =
                    new SrgsSemanticInterpretationTag("$._value = \"" + contact.Key + "\";");

                SrgsItem nameItem = new SrgsItem();
                nameItem.Add(item);
                nameItem.Add(tag);

                oneOf.Add(nameItem);
            }

            SrgsRule nameRule = new SrgsRule("name");

            nameRule.Scope = SrgsRuleScope.Public;
            nameRule.Elements.Add(oneOf);

            SrgsDocument grammarDoc = new SrgsDocument();

            grammarDoc.Rules.Add(nameRule);
            grammarDoc.Root = nameRule;

            speechGrammar.Add(new Grammar(grammarDoc));
        }
Ejemplo n.º 8
0
        static Grammar LoadGrammar(string grammarPathString, bool forceCompile)
        {
            if (grammarPathString == null)
            {
                return(null);
            }

            string compiledGrammarPathString;
            string grammarExtension = Path.GetExtension(grammarPathString);

            if (grammarExtension.Equals(".grxml", StringComparison.OrdinalIgnoreCase))
            {
                compiledGrammarPathString = Path.ChangeExtension(grammarPathString, "cfg");
            }
            else if (grammarExtension.Equals(".cfg", StringComparison.OrdinalIgnoreCase))
            {
                compiledGrammarPathString = grammarPathString;
            }
            else
            {
                throw new FormatException("Grammar file format is unsupported: " + grammarExtension);
            }

            // skip cpmpilation if "cfg" grammar already exists
            if (forceCompile || !File.Exists(compiledGrammarPathString))
            {
                FileStream fs   = new FileStream(compiledGrammarPathString, FileMode.Create);
                var        srgs = new SrgsDocument(grammarPathString);
                SrgsGrammarCompiler.Compile(srgs, fs);
                fs.Close();
            }

            return(new Grammar(compiledGrammarPathString));
        }
Ejemplo n.º 9
0
        public void UstawGramatyke(string path)
        {
            sre.UnloadAllGrammars();
            SrgsDocument doc = new SrgsDocument("../../" + path);

            sre.LoadGrammar(new Grammar(doc, Path.GetFileNameWithoutExtension(path)));
        }
Ejemplo n.º 10
0
        private Grammar CreateGrammar2D()
        {
            SrgsDocument doc = new SrgsDocument();

            doc.PhoneticAlphabet = SrgsPhoneticAlphabet.Ups;
            SrgsRule  rule  = new SrgsRule("check");
            SrgsOneOf oneOf = new SrgsOneOf();
            int       count = phonems.Length;

            for (int i = 0; i < count; i++)
            {
                for (int i2 = 0; i2 < count; i2++)
                {
                    string text          = phonems[i] + phonems[i2];
                    string pronunciation = phonems[i] + " " + phonems[i2];

                    SrgsToken token = new SrgsToken(text);
                    token.Pronunciation = pronunciation;
                    SrgsItem item = new SrgsItem(token);
                    oneOf.Add(item);
                }
            }

            rule.Add(oneOf);
            doc.Rules.Add(rule);
            doc.Root    = rule;
            doc.Culture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
            Grammar grammar = new Grammar(doc);

            return(grammar);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Compile the given grammar to a file
        /// </summary>
        /// <param name="srgDoc">The document to be complied into cfg grammar file</param>
        /// <param name="cfgPath">The full path of the cfg file that will be save to</param>
        public static void CompileGrammarToFile(SrgsDocument srgDoc, string cfgPath)
        {
            FileStream fs = new FileStream(cfgPath, FileMode.Create);

            SrgsGrammarCompiler.Compile(srgDoc, (Stream)fs);
            fs.Close();
        }
Ejemplo n.º 12
0
        //Method to add item dynamically in the grammar
        private void addItemInABalise(SrgsDocument xmlGrammar, string nameOfRule, int idOfBalise, string itemToAdd)
        {
            #region Add item dynamically in the grammar

            //if the balise target by idOfBalise is a "OneOf" balise
            try
            {
                SrgsOneOf oneOfBalise = (SrgsOneOf)xmlGrammar.Rules[nameOfRule].Elements[idOfBalise];
                oneOfBalise.Add(new SrgsItem(itemToAdd));//Add item in the "OneOf" balise
            }
            catch
            {
                //if the balise target by idOfBalise is a "Item" balise
                try
                {
                    SrgsItem itemBalise = (SrgsItem)xmlGrammar.Rules[nameOfRule].Elements[idOfBalise];
                    itemBalise.Add(new SrgsItem(itemToAdd));//Add item in the "Item" balise
                }
                //Otherwise, return a message box error to inform user
                catch
                {
                    // Configure the message box to be displayed
                    string            messageBoxText = "In the method addItemInABalise(), it is only possible to add item after a OneOf balise or a Item balise!";
                    string            caption        = "Error in method addItemInABalise";
                    MessageBoxButtons button         = MessageBoxButtons.OK;
                    MessageBoxIcon    icon           = MessageBoxIcon.Error;
                    MessageBox.Show(messageBoxText, caption, button, icon);// Display message box
                }
            }

            #endregion
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a grammar for main menu options.
        /// </summary>
        /// <returns></returns>
        private Grammar SetupGrammar()
        {
            var options = this.MainMenuConfiguration.Options;

            SrgsOneOf oneOf = new SrgsOneOf();

            foreach (var option in options)
            {
                SrgsItem item = new SrgsItem(option.Index.ToString(CultureInfo.InvariantCulture));

                SrgsSemanticInterpretationTag tag =
                    new SrgsSemanticInterpretationTag("$._value = \"" + option.DtmfCode + "\";");

                SrgsItem digitItem = new SrgsItem();
                digitItem.Add(item);
                digitItem.Add(tag);

                oneOf.Add(digitItem);
            }

            SrgsRule digitRule = new SrgsRule("digit");

            digitRule.Scope = SrgsRuleScope.Public;
            digitRule.Elements.Add(oneOf);

            SrgsDocument grammarDoc = new SrgsDocument();

            grammarDoc.Mode = SrgsGrammarMode.Dtmf;
            grammarDoc.Rules.Add(digitRule);
            grammarDoc.Root = digitRule;

            return(new Grammar(grammarDoc));
        }
        private Grammar GetGrammar()
        {
            SrgsDocument document = new SrgsDocument();

            SrgsRule rootRule = new SrgsRule("directionRule");
            rootRule.Scope = SrgsRuleScope.Public;

            List<SrgsRule> oneTickGrammarDocument = GetDirectionRule(firstNumberEntry, "Tick", directionEntries, "oneTickRule");
            List<SrgsRule> multipleTicksGrammarDocument = GetDirectionRule(numberEntries, "Ticks", directionEntries, "multipleTicksRule");
            List<SrgsRule> oneTickNoBindingWordGrammarDocument = GetDirectionRule(firstNumberEntry, null, directionEntries, "oneTickRuleNoBindingWord");
            List<SrgsRule> multipleTicksNoBindingWordGrammarDocument = GetDirectionRule(numberEntries, null, directionEntries, "multipleTicksRuleNoBindingWord");

            SrgsOneOf oneOfElements = new SrgsOneOf(
                new SrgsItem(new SrgsRuleRef(oneTickGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(multipleTicksGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(oneTickNoBindingWordGrammarDocument[0])),
                new SrgsItem(new SrgsRuleRef(multipleTicksNoBindingWordGrammarDocument[0]))
            );

            rootRule.Add(oneOfElements);

            document.Rules.Add(rootRule);
            document.Rules.Add(oneTickGrammarDocument.ToArray());
            document.Rules.Add(multipleTicksGrammarDocument.ToArray());
            document.Rules.Add(oneTickNoBindingWordGrammarDocument.ToArray());
            document.Rules.Add(multipleTicksNoBindingWordGrammarDocument.ToArray());

            document.Root = rootRule;

            return new Grammar(document);
        }
Ejemplo n.º 15
0
        public IEnumerable <SrgsDocument> GenerateGrammar()
        {
            // Get all interesting special folders
            var myStartMenu = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
            var cmStartMenu = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
            var myDesktop   = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            var cmDesktop   = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
            // Search all link files
            var allFolders = new [] { myStartMenu, cmStartMenu, myDesktop, cmDesktop };
            var lnkFiles   = allFolders.SelectMany(f => Directory.GetFiles(f, "*.lnk", SearchOption.AllDirectories));
            // Extract information from link files
            var lnks = ExtractStartMenuLinks(shell, lnkFiles).Distinct();

            lnkDict = lnks.ToDictionary(k => k.Name, v => v.Path);
            // Create rule for opening
            var keys  = lnkDict.Keys.OrderBy(k => k).ToArray();
            var oRoot = new SrgsRule(RuleNames.First(), new SrgsItem(openPrefix), new SrgsOneOf(keys));

            oRoot.Scope = SrgsRuleScope.Public;
            // Create rule for closing
            var cRoot = new SrgsRule(RuleNames.Last(), new SrgsItem(closePrefix), new SrgsOneOf(keys));

            cRoot.Scope = SrgsRuleScope.Public;
            // Create document for opening
            var oDoc = new SrgsDocument(oRoot);

            oDoc.Mode = SrgsGrammarMode.Voice;
            yield return(oDoc);

            // Create document for closing
            var cDoc = new SrgsDocument(cRoot);

            cDoc.Mode = SrgsGrammarMode.Voice;
            yield return(cDoc);
        }
Ejemplo n.º 16
0
 public Grammar(SrgsDocument srgsDocument, string ruleName, Uri baseUri, object[] parameters)
 {
     Helpers.ThrowIfNull(srgsDocument, "srgsDocument");
     _srgsDocument   = srgsDocument;
     _isSrgsDocument = (srgsDocument != null);
     _baseUri        = baseUri;
     InitialGrammarLoad(ruleName, parameters, false);
 }
Ejemplo n.º 17
0
        public Grammar GetSpeechGrammar()
        {
            SrgsDocument srgsDocument = new SrgsDocument("./Resources/" + GetType().Name + ".srgs");

            AddCustomSpeechGrammarRules(srgsDocument.Rules);

            return(new Grammar(srgsDocument));
        }
Ejemplo n.º 18
0
 protected override SrgsRule[] GetGrammarRules()
 {
     using (var stream = new MemoryStream(Resources.musicContinuePause))
     using (var xmlReader = XmlReader.Create(stream))
     {
         var srgsDocument = new SrgsDocument(xmlReader);
         return srgsDocument.Rules.ToArray();
     }
 }
 public CombinedGrammar(string name, string xml) 
 {
     this.name = name;
     this.xml = xml;
     var xmlread = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(xml)));
     srgsdoc = new SrgsDocument(xmlread);
     compiled = new Grammar(srgsdoc);
     compiled.Name = name;
 }
Ejemplo n.º 20
0
        public void CompileStronglyTypedGrammarToDllFromPath()
        {
            SrgsDocument srgsDoc = CreateSrgsDocument();

            string temp = GetTestFilePath();

            // Cannot compile to assemblies on .NET Core
            Assert.Throws <PlatformNotSupportedException>(() => SrgsGrammarCompiler.CompileClassLibrary(srgsDoc, temp, new string[0], keyFile: null));
        }
Ejemplo n.º 21
0
        public void CompileStronglyTypedGrammarToCfg()
        {
            SrgsDocument srgsDoc = CreateSrgsDocument();

            using var ms = new MemoryStream();
            SrgsGrammarCompiler.Compile(srgsDoc, ms);

            Assert.True(ms.Position > 0);
        }
Ejemplo n.º 22
0
        public Grammar GetSpeechGrammar()
        {
            SrgsDocument srgsDocument = new SrgsDocument("./Assets/" + GetType().Name + ".srgs");

            AddCustomSpeechGrammarRules(srgsDocument.Rules);
            Grammar grammar = new Grammar(srgsDocument);

            return(grammar);
        }
Ejemplo n.º 23
0
        private static void LoadSRGSGrammar()
        {
            //builder = new GrammarBuilder(Choices);
            //document = new SrgsDocument(builder);
            //grammar = new Grammar(document);

            // Create an SrgsDocument, create a new rule and set its scope to public.
            document = new SrgsDocument
            {
                PhoneticAlphabet = SrgsPhoneticAlphabet.Ups
            };
            //document.PhoneticAlphabet = SrgsPhoneticAlphabet.Sapi;

            //SrgsRule wordRule = (new SrgsRule("word", new SrgsElement[] { oneOfWord }));
            SrgsRule wordRule = new SrgsRule("word")
            {
                Scope = SrgsRuleScope.Public
            };

            SrgsOneOf oneOfWord = new SrgsOneOf(new SrgsItem[] { new SrgsItem("aardvark"),
                                                                 new SrgsItem("beaver"), new SrgsItem("cheetah") });

            SrgsItem  wordItem = new SrgsItem();
            SrgsToken token    = new SrgsToken("whatchamacallit")
            {
                Pronunciation = "W AE T CH AE M AE K AA L IH T"
            };

            wordItem.Add(token);
            //oneOfWord = new SrgsOneOf();
            oneOfWord.Add(wordItem);

            wordRule.Add(oneOfWord);

            //// Create the rule from the SrgsOneOf objects.
            //SrgsRule slangRule = new SrgsRule("slang", wordItem);
            //// Build an SrgsDocument object from the rule and set the phonetic alphabet.
            //SrgsDocument tokenPron = new SrgsDocument(slangRule);

            //// Create a Grammar object from the SrgsDocument and load it to the recognizer.
            //Grammar slangGrammar = new Grammar(tokenPron);
            //slangGrammar.Name = ("Slang Pronunciation");
            //RecEngine.LoadGrammarAsync(slangGrammar);

            //// Add references to winnerRule for ruleEurope.
            //wordRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem (new SrgsRuleRef(ruleEurope)))}));

            // Add all the rules to the document and set the root rule of the document.
            document.Rules.Add(new SrgsRule[] { wordRule });
            document.Root = wordRule;

            Grammar grammar = new Grammar(document);

            RecEngine.LoadGrammar(grammar);
        }
Ejemplo n.º 24
0
        private void srBtn_Click(object sender, EventArgs e)
        {
            ttsListner = new TcpListener(ttsPort);
            //启动tts接收线程
            //ttsSp.Speak("yes I received");
            ttsThread = new Thread(new ThreadStart(ttsReceiveThread));
            ttsThread.Start();
            srRichTextBox.AppendText("tts接收已激活\n");
            if (this.cmdfilecomboBox.Text != "")
            {
                if (this.cmdfilecomboBox.Text == "GPSR.ini")//GPSR输入语法
                {
                    srPicBox.Image = global::XM_speech2._0.Properties.Resources.msg_ok;
                    remoteIp       = srIpTextBox.Text;
                    remotePort     = Convert.ToInt32(srPortTextBox.Text);
                    sre.SetInputToDefaultAudioDevice();//默认的语音输入设备
                    SrgsDocument srg = new SrgsDocument("GPSR.xml");
                    this.loadCmdFile("GPSR.xml");
                    sre.LoadGrammar(new Grammar(srg));
                }
                else
                {
                    srPicBox.Image = global::XM_speech2._0.Properties.Resources.msg_ok;
                    remoteIp       = srIpTextBox.Text;
                    remotePort     = Convert.ToInt32(srPortTextBox.Text);
                    cmdFile        = cmdfilecomboBox.Text;
                    sre.SetInputToDefaultAudioDevice();//默认的语音输入设备
                    GrammarBuilder gb   = new GrammarBuilder();
                    string[]       cmds = this.loadCmdFile(cmdFile);
                    gb.Append(new Choices(cmds));
                    Grammar grammar = new Grammar(gb);
                    sre.LoadGrammar(grammar);
                }

                if (this.cmdfilecomboBox.Text == "GPSR.ini")
                {
                    sre.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(sre_GPSRrecognized);
                    sre.SpeechDetected   += new EventHandler <SpeechDetectedEventArgs>(sre_GPSRDetected);
                    Console.WriteLine("ing...");
                }
                else
                {
                    Console.WriteLine("ing...");
                    sre.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(sre_SpeechRecognized);
                    sre.SpeechDetected   += new EventHandler <SpeechDetectedEventArgs>(sre_SpeechDetected);
                }
                sre.RecognizeAsync(RecognizeMode.Multiple);//异步调用识别引擎,允许多次识别(否则程序只响应你的一句话)
            }
            if (this.cmdfilecomboBox.Text == "emmergency.ini")
            {
                Thread.Sleep(5000);
                ttsSp.Speak("I can't find you, please come here");
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Generate a list of grammars with the annotations attach to the
        /// grammars' semantic tag.
        /// </summary>
        /// <param name="list"></param>
        /// <param name="annotations"></param>
        /// <returns></returns>
        public static List <SrgsDocument> GenerateGrammars(string[] list, string[] annotations)
        {
            String timeStamp = GetTimestamp();

            Debug.WriteLine("Before generate grammar time:" + timeStamp);

            List <SrgsDocument> srgsDocs = new List <SrgsDocument>();

            for (int i = 0; i < list.Length; i++)
            {
                SrgsRule  rule = new SrgsRule("index_" + i);
                SrgsOneOf so   = new SrgsOneOf();
                for (int j = i; j < list.Length && j < i + EBookInteractiveSystem.MAX_WORDS_IN_SPEECH; j++)
                {
                    string        ea   = "";
                    List <string> anno = new List <string>();
                    for (int k = i; k <= j; k++)
                    {
                        ea += list[k] + " ";
                        if (!anno.Contains(annotations[k]))
                        {
                            anno.Add(annotations[k]);
                        }
                    }
                    string annotate = "";
                    foreach (string ann in anno)
                    {
                        if (ann.Trim().Length > 0)
                        {
                            annotate += ann;
                        }
                    }
                    ea = ea.TrimEnd();
                    SrgsItem si = new SrgsItem(ea);
                    if (annotate.Length > 0)
                    {
                        annotate = "out.annotation=\"" + annotate + "\";";
                    }
                    si.Add(new SrgsSemanticInterpretationTag(annotate + "out.startIndex=\"" + i + "\";"));
                    so.Add(si);
                }
                rule.Add(so);
                SrgsDocument srgsDoc = new SrgsDocument();
                srgsDoc.Rules.Add(rule);
                srgsDoc.Root = rule;
                srgsDocs.Add(srgsDoc);
            }
            String after = GetTimestamp();

            Debug.WriteLine("after generate grammar time:" + after);
            return(srgsDocs);
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            var c = new CultureInfo("en-US");
            // Create a new Speech Recognizer
            var recognizer  = new SpeechRecognitionEngine(c);
            var recognizer2 = new SpeechRecognitionEngine(c);

            //recognizer.UpdateRecognizerSetting("CFGConfidenceRejectionThreshold", 30);

            recognizer.InitialSilenceTimeout = TimeSpan.FromMilliseconds(0);
            //recognizer.EndSilenceTimeout = TimeSpan.FromMilliseconds(0);
            //recognizer.EndSilenceTimeoutAmbiguous = TimeSpan.FromMilliseconds(0);
            Console.WriteLine(recognizer.InitialSilenceTimeout);

            Console.WriteLine(recognizer.EndSilenceTimeout);
            Console.WriteLine(recognizer.EndSilenceTimeoutAmbiguous.TotalSeconds);
            // Configure the input to the recognizer.
            //recognizer.SetInputToWaveFile(@"C:\Users\march\Source\Repos\renzomarchena\SpeechRecognitionTest\SpeechRecognitionTest\2488415658_NYL_P410SM8R_149520478_101826_NYL_P410SM8R.wav");
            recognizer.SetInputToWaveFile(@"2488415658_NYL_P410SM8R_149520478_101826_NYL_P410SM8R.wav");
            recognizer2.SetInputToWaveFile(@"2488415658_NYL_P410SM8R_149520478_101826_NYL_P410SM8R.wav");

            var srgsDocument = new SrgsDocument(@"grammar.grxml");

            var srgsDocument2 = new SrgsDocument(@"KeyPhrases.grml");

            // Create the Grammar instance.

            var g = new Grammar(srgsDocument);

            g.Name = "numbers";
            var g2 = new Grammar(srgsDocument2);

            // Load the Grammar into the Speech Recognizer

            recognizer.LoadGrammar(g);
            recognizer2.LoadGrammar(g2);
            Console.WriteLine(recognizer.Grammars.Count);
            // Register for Speech Recognition Event Notification
            recognizer.SpeechRecognized    += new EventHandler <SpeechRecognizedEventArgs>(Recognizer_SpeechRecognized);
            recognizer.RecognizeCompleted  += new EventHandler <RecognizeCompletedEventArgs>(Recognizer_RecognizeCompleted);
            recognizer2.SpeechRecognized   += new EventHandler <SpeechRecognizedEventArgs>(Recognizer_SpeechRecognized);
            recognizer2.RecognizeCompleted += new EventHandler <RecognizeCompletedEventArgs>(Recognizer_RecognizeCompleted);
            completed = false;
            recognizer.RecognizeAsync(RecognizeMode.Multiple);
            recognizer2.RecognizeAsync(RecognizeMode.Multiple);
            while (!completed)
            {
                Thread.Sleep(333);
            }

            Console.ReadLine();
        }
Ejemplo n.º 27
0
        public static void BuildGrammar(String GrammarFileName)
        {
            GrammarFile     = GrammarFileName;
            GrammarFilePath = "C:\\Users\\TwoFa\\source\\repos\\MSP-PoC\\ASR\\XmlFiles\\" + GrammarFileName;

            Console.WriteLine(GrammarFileName);

            RecognitionEngine.UnloadAllGrammars();
            grammarDoc = new SrgsDocument(GrammarFilePath);
            Grammar grammar = new Grammar(grammarDoc);

            RecognitionEngine.LoadGrammar(grammar);
        }
Ejemplo n.º 28
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.º 29
0
        public void RenderButtons(IList <string> buttons, bool twoColumn)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                ClearAll();
                SrgsRule root      = new SrgsRule("command");
                SrgsOneOf commands = new SrgsOneOf();
                root.Add(new SrgsItem(commands));

                int numCols              = twoColumn ? 2 : 1;
                int numRows              = ((buttons.Count - 1) / numCols) + 1;
                ButtonsContainer.Rows    = numRows;
                ButtonsContainer.Columns = numCols;

                for (int i = 0; i < numRows * numCols; ++i)
                {
                    int index = (i % numCols) * numRows + i / numCols;
                    UIElement b;
                    if (index < buttons.Count)
                    {
                        string s = buttons[index];
                        b        = new Button()
                        {
                            Content = new TextBlock()
                            {
                                TextWrapping = TextWrapping.Wrap,
                                Text         = s,
                            },
                        };

                        commands.Add(new SrgsItem(s));
                    }
                    else
                    {
                        b = new TextBlock();
                    }

                    ButtonsContainer.Children.Add(b);
                }

                if (commands.Items.Count > 0 && EnableSpeechRecognition && _micAvailable)
                {
                    SrgsDocument doc = new SrgsDocument();
                    doc.Rules.Add(root);
                    doc.Root = root;
                    speechEngine.LoadGrammar(new Grammar(doc));
                    speechEngine.RecognizeAsync(RecognizeMode.Multiple);
                }
            }), null);
        }
Ejemplo n.º 30
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.º 31
0
        private SrgsDocument CreateSrgsDocument()
        {
            SrgsDocument srgsDoc = new SrgsDocument();
            SrgsRule     rule    = new SrgsRule("someRule");
            SrgsItem     item    = new SrgsItem("someItem");

            item.Add(new SrgsSemanticInterpretationTag("out = \"foo\";"));
            SrgsOneOf oneOf = new SrgsOneOf(item);

            rule.Add(oneOf);

            srgsDoc.Rules.Add(rule);
            srgsDoc.Root = rule;
            return(srgsDoc);
        }
Ejemplo n.º 32
0
        private void LoadAndCompileCfgData(bool isImportedGrammar, bool stgInit)
        {
            Stream stream = IsStg ? LoadCfgFromResource(stgInit) : LoadCfg(isImportedGrammar, stgInit);

            SrgsRule[] array = RunOnInit(IsStg);
            if (array != null)
            {
                MemoryStream memoryStream = CombineCfg(_ruleName, stream, array);
                stream.Close();
                stream = memoryStream;
            }
            _cfgData = Helpers.ReadStreamToByteArray(stream, (int)stream.Length);
            stream.Close();
            _srgsDocument = null;
            _appStream    = null;
        }
Ejemplo n.º 33
0
        public Example()
        {
            doc = new SrgsDocument();

            SrgsRule whatis = new SrgsRule("whatis");

            SrgsItem question = new SrgsItem("what is");
            SrgsOneOf closers = new SrgsOneOf("life", "the time", "love", "happiness", "two plus two");

            whatis.Add(question);
            whatis.Add(closers);
            whatis.Scope = SrgsRuleScope.Public;

            doc.Rules.Add(whatis);
            doc.Root = whatis;
        }
Ejemplo n.º 34
0
        internal static void CompileStream(SrgsDocument srgsGrammar, string filename, Stream stream, bool fOutputCfg, string[] referencedAssemblies, string keyFile)
        {
            ISrgsParser srgsParser = new SrgsDocumentParser(srgsGrammar.Grammar);
            List <CustomGrammar.CfgResource> cfgResources = new List <CustomGrammar.CfgResource>();
            StringBuilder stringBuilder = new StringBuilder();

            srgsGrammar.Grammar.Validate();
            CultureInfo culture;
            object      obj = CompileStream(1, srgsParser, null, filename, stream, fOutputCfg, stringBuilder, cfgResources, out culture, referencedAssemblies, keyFile);

            if (!fOutputCfg)
            {
                CustomGrammar customGrammar = new CustomGrammar();
                customGrammar.Combine((CustomGrammar)obj, stringBuilder.ToString());
                customGrammar.CreateAssembly(filename, cfgResources);
            }
        }
        private Grammar GetMappingGrammar()
        {
            SrgsDocument document = new SrgsDocument();
            mapping = (SpeechBasedInputMapping)speechInput.Mapping;

            SrgsRule rootRule = GetRootRule();
            rootRule.Scope = SrgsRuleScope.Public;

            document.Root = rootRule;

            foreach (KeyValuePair<String, SrgsRule> rule in usedRules)
            {
                document.Rules.Add(rule.Value);
            }
            usedRules.Clear();

            return new Grammar(document);
        }
Ejemplo n.º 36
0
 public override void Invoke()
 {
     if (grammars.ContainsKey(name))
     {
         var other = grammars[name];
         Program.se.UnloadAllGrammars();
         grammars2.Remove(other.grammar);
         grammars.Remove(other.name);
     }
     var doc = new SrgsDocument(new XmlTextReader(new MemoryStream(Properties.Resources.numbers)));
     var alt = new SrgsOneOf();
     foreach (var rule in rules)
         alt.Add(new SrgsItem(new SrgsElement[] { rule.Value.Build(doc), new SrgsNameValueTag(rule.Key) }));
     var root = new SrgsRule(Program.InternalMarker + "root", alt);
     doc.Rules.Add(root);
     doc.Root = root;
     doc.Debug = true;
     grammar = new Grammar(doc);
     grammars.Add(name, this);
     grammars2.Add(grammar, this);
     Console.WriteLine("Created grammar " + name);
 }
Ejemplo n.º 37
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;
        }
Ejemplo n.º 38
0
 public abstract SrgsItem Build(SrgsDocument doc);
Ejemplo n.º 39
0
 public override SrgsItem Build(SrgsDocument doc)
 {
     return new SrgsItem(
         new SrgsElement[]
         {
             new SrgsItem(start),
             new SrgsRuleRef(doc.Rules["positiveIntegers"]),
         });
 }
Ejemplo n.º 40
0
        private void srBtn_Click(object sender, EventArgs e)
        {
            ttsListner = new TcpListener(ttsPort);
            //启动tts接收线程
            //ttsSp.Speak("yes I received");
            ttsThread = new Thread(new ThreadStart(ttsReceiveThread));
            ttsThread.Start();
            srRichTextBox.AppendText("tts接收已激活\n");
            if (this.cmdfilecomboBox.Text != "")
            {
                if (this.cmdfilecomboBox.Text == "GPSR.ini")//GPSR输入语法
                {
                    srPicBox.Image = global::XM_speech2._0.Properties.Resources.msg_ok;
                    remoteIp = srIpTextBox.Text;
                    remotePort = Convert.ToInt32(srPortTextBox.Text);
                    sre.SetInputToDefaultAudioDevice();//默认的语音输入设备
                    SrgsDocument srg = new SrgsDocument("GPSR.xml");
                    this.loadCmdFile("GPSR.xml");
                    sre.LoadGrammar(new Grammar(srg));
                }
                else
                {
                    srPicBox.Image = global::XM_speech2._0.Properties.Resources.msg_ok;
                    remoteIp = srIpTextBox.Text;
                    remotePort = Convert.ToInt32(srPortTextBox.Text);
                    cmdFile = cmdfilecomboBox.Text;
                    sre.SetInputToDefaultAudioDevice();//默认的语音输入设备
                    GrammarBuilder gb = new GrammarBuilder();
                    string[] cmds = this.loadCmdFile(cmdFile);
                    gb.Append(new Choices(cmds));
                    Grammar grammar = new Grammar(gb);
                    sre.LoadGrammar(grammar);
                }

                if (this.cmdfilecomboBox.Text == "GPSR.ini")
                {

                    sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_GPSRrecognized);
                    sre.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(sre_GPSRDetected);
                    Console.WriteLine("ing...");
                }
                else
                {
                    Console.WriteLine("ing...");
                    sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
                    sre.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(sre_SpeechDetected);
                }
                sre.RecognizeAsync(RecognizeMode.Multiple);//异步调用识别引擎,允许多次识别(否则程序只响应你的一句话)
            }
            if(this.cmdfilecomboBox.Text=="emmergency.ini")
            {
                Thread.Sleep(5000);
                ttsSp.Speak("I can't find you, please come here");
                
            }
        }
Ejemplo n.º 41
0
 public override SrgsItem Build(SrgsDocument doc)
 {
     return new SrgsItem(
         new SrgsElement[]
         {
             new SrgsItem(start),
             new SrgsRuleRef(new Uri("grammar:dictation")),
         });
 }
Ejemplo n.º 42
0
 public override SrgsItem Build(SrgsDocument doc)
 {
     return new SrgsItem(start);
 }
Ejemplo n.º 43
0
 Grammar CreateGrammar(string name, SrgsDocument doc)
 {
     Grammar g = new Grammar(doc);
     g.Name = name;
     return g;
 }
Ejemplo n.º 44
0
        SrgsItem CreateNumberSRGS(string prepend, SrgsDocument doc)
        {
            SrgsItem digit_0 = new SrgsItem("zero");
            digit_0.Add(new SrgsNameValueTag(prepend+"0", 0));
            SrgsItem digit_1 = new SrgsItem("one");
            digit_1.Add(new SrgsNameValueTag(prepend + "1", 1));
            SrgsItem digit_2 = new SrgsItem("two");
            digit_2.Add(new SrgsNameValueTag(prepend + "2", 2));
            SrgsItem digit_3 = new SrgsItem("three");
            digit_3.Add(new SrgsNameValueTag(prepend + "3", 3));
            SrgsItem digit_4 = new SrgsItem("four");
            digit_4.Add(new SrgsNameValueTag(prepend + "4", 4));
            SrgsItem digit_5 = new SrgsItem("five");
            digit_5.Add(new SrgsNameValueTag(prepend + "5", 5));
            SrgsItem digit_6 = new SrgsItem("six");
            digit_6.Add(new SrgsNameValueTag(prepend + "6", 6));
            SrgsItem digit_7 = new SrgsItem("seven");
            digit_7.Add(new SrgsNameValueTag(prepend + "7", 7));
            SrgsItem digit_8 = new SrgsItem("eight");
            digit_8.Add(new SrgsNameValueTag(prepend + "8", 8));
            SrgsItem digit_9 = new SrgsItem("nine");
            digit_9.Add(new SrgsNameValueTag(prepend + "9", 9));
            SrgsItem digit_10 = new SrgsItem("ten");
            digit_10.Add(new SrgsNameValueTag(prepend + "10", 10));
            SrgsItem digit_11 = new SrgsItem("eleven");
            digit_11.Add(new SrgsNameValueTag(prepend + "11", 11));
            SrgsItem digit_12 = new SrgsItem("twelve");
            digit_12.Add(new SrgsNameValueTag(prepend + "12", 12));
            SrgsItem digit_13 = new SrgsItem("thirteen");
            digit_13.Add(new SrgsNameValueTag(prepend + "13", 13));
            SrgsItem digit_14 = new SrgsItem("fourteen");
            digit_14.Add(new SrgsNameValueTag(prepend + "14", 14));
            SrgsItem digit_15 = new SrgsItem("fifteen");
            digit_15.Add(new SrgsNameValueTag(prepend + "15", 15));
            SrgsItem digit_16 = new SrgsItem("sixteen");
            digit_16.Add(new SrgsNameValueTag(prepend + "16", 16));
            SrgsItem digit_17 = new SrgsItem("seventeen");
            digit_17.Add(new SrgsNameValueTag(prepend + "17", 17));
            SrgsItem digit_18 = new SrgsItem("eighteen");
            digit_18.Add(new SrgsNameValueTag(prepend + "18", 18));
            SrgsItem digit_19 = new SrgsItem("nineteen");
            digit_19.Add(new SrgsNameValueTag(prepend + "19", 19));

            SrgsItem digit_20 = new SrgsItem("twenty");
            digit_20.Add(new SrgsNameValueTag(prepend + "20", 20));
            SrgsItem digit_30 = new SrgsItem("thirty");
            digit_30.Add(new SrgsNameValueTag(prepend + "30", 30));
            SrgsItem digit_40 = new SrgsItem("fourty");
            digit_40.Add(new SrgsNameValueTag(prepend + "40", 40));
            SrgsItem digit_50 = new SrgsItem("fifty");
            digit_50.Add(new SrgsNameValueTag(prepend + "50", 50));
            SrgsItem digit_60 = new SrgsItem("sixty");
            digit_60.Add(new SrgsNameValueTag(prepend + "60", 60));

            SrgsOneOf digit_onepart = new SrgsOneOf(digit_0, digit_1, digit_2, digit_3,
                digit_4, digit_5, digit_6, digit_7, digit_8, digit_9, digit_10,
                digit_11, digit_12, digit_13, digit_14, digit_15, digit_16, digit_17, digit_18, digit_19,
                digit_20, digit_30, digit_40, digit_50, digit_60);
            SrgsOneOf digit_single = new SrgsOneOf(digit_1, digit_2, digit_3,
                digit_4, digit_5, digit_6, digit_7, digit_8, digit_9);
            SrgsOneOf digit_second = new SrgsOneOf(digit_20, digit_30, digit_40, digit_50, digit_60);
            SrgsRule digit_twopart = new SrgsRule(prepend+"_twodigit");
            digit_twopart.Add(digit_second);
            digit_twopart.Add(digit_single);
            doc.Rules.Add(digit_twopart);
            SrgsOneOf number = new SrgsOneOf(
                new SrgsItem(digit_onepart), new SrgsItem(new SrgsRuleRef(digit_twopart)));

            SrgsItem ret = new SrgsItem(number);
            ret.Add(new SrgsNameValueTag(prepend, "true"));
            return ret;
        }
Ejemplo n.º 45
0
 SrgsRuleRef SrgsActionsFromCapabilities(DeviceCapabilities caps, SrgsDocument doc)
 {
     SrgsRule r;
     if (caps_rules.Keys.Contains(caps.Caps))
     {
         r = caps_rules[caps.Caps];
     }
     else
     {
         List<string> capsAsString = caps.Actions;
         if (capsAsString == null || capsAsString.Count == 0) return null;
         SrgsOneOf actions = new SrgsOneOf();
         foreach (string s in capsAsString)
         {
             SrgsItem si = new SrgsItem(s);
             //si.Add(new SrgsSemanticInterpretationTag(" out = \"" + s + "\";"));
             si.Add(new SrgsNameValueTag("action", s));
             actions.Add(si);
         }
         r = new SrgsRule(AudioRecog_SAPI.SrgsCleanupID("caps_" + caps.CapsAsIntString), actions);
         doc.Rules.Add(r);
         caps_rules.Add(caps.Caps, r);
     }
     //return new SrgsRuleRef(r, "action");
     return new SrgsRuleRef(r);
 }
Ejemplo n.º 46
0
 /// <summary>
 /// Load the grammar from the JarvisSettings.
 /// </summary>
 /// <returns>Grammar</returns>
 public override Grammar GetGrammar()
 {
     SrgsDocument xmlGrammar = new SrgsDocument(JarvisSettings.GrammarFile);
     return new Grammar(xmlGrammar);
 }
Ejemplo n.º 47
0
        void AddGrammar(string name, SrgsDocument doc)
        {
            lock (mDocs)
            {
                if (mDocs.ContainsKey(name)) mDocs[name] = doc;
                mDocs.Add(name, doc);
            }

            lock (engines)
            {
                foreach (AudioInstance ai in engines)
                {
                    if (!ai.Active)
                    {
                        ai.engine.LoadGrammar(CreateGrammar(name, doc));
                        ai.NeedNewGrammar = false;
                    }
                    else ai.NeedNewGrammar = true;
                }
            }
        }
Ejemplo n.º 48
0
        public static SrgsDocument BuildSrgsGrammar(CultureInfo cultureInfo)
        {
            SrgsDocument document = new SrgsDocument();
            document.Culture = cultureInfo;

            // 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", "fallback", "fall back", "regroup", "join up", "rally on me", "rally to me" }, new uint[] { 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 uint[] { 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", "go back", "back up" }, new uint[] { 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", "go left" }, new uint[] { 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", "go right" }, new uint[] { 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", "halt", "stay there", "stay here" }, new uint[] { 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", "wait" }, new uint[] { 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", "get to cover", "hide" }, new uint[] { Keys.One, Keys.Eight }, subjectRef);
            commandObjects.Add("COVER", cover);
            commandSet.Add(cover.Item);

            // Next waypoint (9)
            Command nextWaypoint = new Command("NEXTWAYPOINT", new string[] { "next waypoint", "go to the next waypoint" }, new uint[] { 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", "open target menu", "targets" }, new uint[] { Keys.Two }, subjectRef);
            commandObjects.Add("OPENTARGET", openTargetMenu);
            commandSet.Add(openTargetMenu.Item);

            // cancel target (1)
            Command cancelTarget = new Command("CANCELTARGET", new string[] { "cancel target", "cancel targets", "no target" }, new uint[] { 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 uint[] { 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", "cease fire" }, new uint[] { 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 uint[] { Keys.Three, Keys.Three }, subjectRef);
            commandObjects.Add("FIRE", fire);
            commandSet.Add(fire.Item);

            // engage (4)
            Command engage = new Command("ENGAGE", new string[] { "engage", "move to engage" }, new uint[] { 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 uint[] { Keys.Three, Keys.Five }, subjectRef);
            commandObjects.Add("ENGAGEATWILL", enageAtWill);
            commandSet.Add(enageAtWill.Item);

            // disengage (6)
            Command disengage = new Command("DISENGAGE", new string[] { "disengage" }, new uint[] { 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 uint[] { 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 uint[] { Keys.One });
            direction.Add(new string[] { "north east" }, "NORTHEAST", new uint[] { Keys.Two });
            direction.Add(new string[] { "east" }, "EAST", new uint[] { Keys.Three });
            direction.Add(new string[] { "south east" }, "SOUTHEAST", new uint[] { Keys.Four });
            direction.Add(new string[] { "south" }, "SOUTH", new uint[] { Keys.Five });
            direction.Add(new string[] { "south west" }, "SOUTHWEST", new uint[] { Keys.Six });
            direction.Add(new string[] { "west" }, "WEST", new uint[] { Keys.Seven });
            direction.Add(new string[] { "north west" }, "NORTHWEST", new uint[] { Keys.Eight });

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

            Command watch = new Command("WATCH", new string[] { "watch", "watch the"}, new uint[] { 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", "surpress" }, new uint[] { 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 mount menu", "open mount menu", "show vehicles", "mount menu", "get in vehicle" }, new uint[] { Keys.Four }, subjectRef);
            commandObjects.Add("OPENMOUNT", openMountMenu);
            commandSet.Add(openMountMenu.Item);

            // dismount (1)
            Command dismount = new Command("DISMOUNT", new string[] { "dismount", "get out" }, new uint[] { 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", "do action", "open action menu", "actions" }, new uint[] { 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 uint[] { 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 uint[] { Keys.Seven, Keys.Two }, subjectRef);
            commandObjects.Add("COMBAT", combat);
            commandSet.Add(combat.Item);

            // aware (3)
            Command aware = new Command("AWARE", new string[] { "aware", "alert", "aware mode", "stay sharp", "stay frosty", "stay alert" }, new uint[] { 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", "safe" }, new uint[] { 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", "stand" }, new uint[] { 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 uint[] { 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", "down" }, new uint[] { 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 uint[] { 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"}, new uint[] { 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" }, new uint[] { 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" }, new uint[] { 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" }, new uint[] { 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" }, new uint[] { 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" }, new uint[] { 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" }, new uint[] { 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" }, new uint[] { 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" }, new uint[] { 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 uint[] { Keys.One });
            team.Add(new string[] { "team green", "green" }, "GREEN", new uint[] { Keys.Two });
            team.Add(new string[] { "team blue", "blue" }, "BLUE", new uint[] { Keys.Three });
            team.Add(new string[] { "team yellow", "yellow" }, "YELLOW", new uint[] { Keys.Four });
            team.Add(new string[] { "team white", "white" }, "WHITE", new uint[] { Keys.Five });

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

            Command assignTeam = new Command("ASSIGN", new string[] { "assign", "assign to", "add to", "switch to" }, new uint[] { 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;

            return document;
        }
Ejemplo n.º 49
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.º 50
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 is_awake = new SrgsOneOf(new string[] { "i'm awake", "turn off the alarm", "i am awake"});

            SrgsRule root_rule = new SrgsRule("rootrule");
            root_rule.Add(new SrgsItem("Holly"));
            SrgsItem cmd = new SrgsItem(is_awake);
            cmd.Add(new SrgsNameValueTag("command", "turn off alarm"));
            root_rule.Add(cmd);
            root_rule.Add(new SrgsItem("please"));
            doc.Rules.Add(root_rule);
            doc.Root = root_rule;

            currentSrgsDoc = doc;
            return currentSrgsDoc;
        }
Ejemplo n.º 51
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;
        }