public void saveProfileProceed()
        {
            t.log("ProfileManager.saveProfileProceed()");


            int NoOfCommands = fm.commandManager.commands.Count;
            int cnt          = 0;
            int percent      = 0;

            String xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";

            xmlString += "<xml>" + "\n\n";

            foreach (CommandVO cvo in fm.commandManager.commands)
            {
                cnt++;

                xmlString += "\t" + "<command>" + "\n";
                xmlString += "\t\t" + "<speech>" + cvo.speech + "</speech>" + "\n";
                xmlString += "\t\t" + "<command_sequence delayBetweenCommands=\"" + cvo.delayBetweenCommands + "\">" + "\n";

                for (int i = 0; i < cvo.commandItems.Count; i++)
                {
                    CommandItemVO civo = cvo.commandItems[i];
                    t.log("civo.type = " + civo.type);

                    switch (civo.type)
                    {
                    case "run application":
                        xmlString += "\t\t\t" + "<item type=\"" + civo.type + "\">\n";
                        xmlString += "\t\t\t\t" + "<path>" + civo.applicationPath + "</path>\n";
                        xmlString += "\t\t\t\t" + "<params>" + civo.applicationParams + "</params>\n";
                        xmlString += "\t\t\t" + "</item>" + "\n";
                        break;

                    case "clipboard":
                        xmlString += "\t\t\t" + "<item type=\"" + civo.type + "\" autoPaste=\"" + DTools.boolToNumberString(civo.clipboardAutoPaste) + "\">";
                        xmlString += "<![CDATA[" + civo.clipboard + "]]>";
                        xmlString += "</item>" + "\n";
                        break;

                    case "clipboard to var":
                        xmlString += "\t\t\t" + "<item type=\"" + civo.type + "\" var=\"" + civo.appVarIndex + "\"></item>\n";
                        break;

                    case "var to clipboard":
                        xmlString += "\t\t\t" + "<item type=\"" + civo.type + "\" var=\"" + civo.appVarIndex + "\"></item>\n";
                        break;

                    case "key":
                        xmlString += "\t\t\t" + "<item type=\"" + civo.type + "\" ";
                        xmlString += "ctrl=\"" + DTools.boolToNumberString(civo.ctrlPressed) + "\" ";
                        xmlString += "alt=\"" + DTools.boolToNumberString(civo.altPressed) + "\" ";
                        xmlString += "shift=\"" + DTools.boolToNumberString(civo.shiftPressed) + "\">";
                        xmlString += civo.key;
                        xmlString += "</item>" + "\n";
                        break;

                    case "delay":
                        xmlString += "\t\t\t" + "<item type=\"" + civo.type + "\" duration=\"" + civo.delayTime.ToString() + "\"></item>\n";
                        break;

                    case "focus on application":
                        xmlString += "\t\t\t" + "<item type=\"" + civo.type + "\" ";
                        xmlString += "delayBeforeFocus=\"" + civo.delayBeforeFocus.ToString() + "\" ";
                        xmlString += "stopIfFocusNotFound=\"" + DTools.boolToNumberString(civo.stopIfFocusNotFound) + "\" ";
                        xmlString += "/>\n";
                        break;
                    }
                }

                xmlString += "\t\t" + "</command_sequence>" + "\n";
                xmlString += "\t" + "</command>" + "\n\n";
            }

            xmlString += "</xml>" + "\n";

            //XDocument xDoc = XDocument.Load(xmlString);

            t.log(xmlString);


            //FileStream fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None);


            String profilePath = Vars.profilePath + "/" + activeProfile + ".xml";

            try
            {
                //xDoc.Save(fileStream);
                File.WriteAllText(profilePath, xmlString, Encoding.UTF8);
                fm.setStatus("Profile saved!");
                fm.speechRecognizer.startListening();
            }
            catch
            {
                fm.setStatus("Unable to save profile!");
            }

            fm.Show();

            fps.Close();
        }
Example #2
0
        // -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -



        // -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
        public void getCommandsFromLoadedProfile()
        {
            t.log("CommandManager.getCommandsFromLoadedProfile()");

            fm.setStatus("Parsing profile commands...");

            commands = new List <CommandVO>();

            XmlNodeList xmlCommandsList = fm.profileManager.xmlDoc.SelectNodes("//command");

            //t.log("\t" + "xmlCommandsList.Count = " + xmlCommandsList.Count);
            //t.log("\t" + "xmlCommandsList.GetType = " + xmlCommandsList.GetType());


            t.log("------------------------------------------------------------");
            foreach (XmlNode commandRootNode in xmlCommandsList)
            {
                //t.log("\t" + commandRootNode.ChildNodes[0].InnerText.ToString());

                // Parse the outer VO (ID = String speech)
                CommandVO cvo = new CommandVO();
                cvo.speech = commandRootNode.ChildNodes[0].InnerText.ToString();

                // Parse the inner VO (list)
                XmlNodeList xmlCommandItems = commandRootNode.SelectNodes("command_sequence/item");
                //t.log("\t\t" + "CommandItem: " + xmlCommandItems.ToString());

                t.log("\n");
                t.log("\t\t" + "command = " + cvo.speech);


                //Console.WriteLine("###### " + commandRootNode.ChildNodes[1].OuterXml.ToString());
                foreach (XmlNode commandItemNode in xmlCommandItems)
                {
                    //t.log("\t\t" + "CommandItem: " + commandItemNode.OuterXml.ToString());
                    //t.log("\t\t\t" + "XML = " + commandItemNode.OuterXml.ToString());

                    String commandItemType = commandItemNode.Attributes[0].Value.ToString();

                    CommandItemVO civo = new CommandItemVO();
                    civo.type = commandItemType;


                    int index = -1;

                    t.log("\t\t" + "commandItemType = " + commandItemType);
                    switch (commandItemType)
                    {
                    case "run application":
                        t.log("\t\t\t" + commandItemNode.ChildNodes[0].InnerXml.ToString());
                        civo.applicationPath = commandItemNode.ChildNodes[0].InnerXml.ToString();

                        t.log("\t\t\t" + commandItemNode.ChildNodes[1].InnerXml.ToString());
                        civo.applicationParams = commandItemNode.ChildNodes[1].InnerXml.ToString();
                        break;

                    case "clipboard":
                        t.log("\t\t\t" + "commandItemNode.InnerText = " + commandItemNode.InnerText.ToString());
                        t.log("\t\t\t" + "commandItemNode.Attributes[1].Value = " + commandItemNode.Attributes[1].Value.ToString());

                        civo.clipboard          = commandItemNode.InnerText.ToString();
                        civo.clipboardAutoPaste = DTools.intStringToBoolean(commandItemNode.Attributes[1].Value.ToString());


                        break;

                    case "clipboard to var":
                        index               = int.Parse(commandItemNode.Attributes[1].Value.ToString());
                        civo.appVarIndex    = index;
                        civo.appVars[index] = Clipboard.GetText();
                        //t.log("\t\t\t" + "index = " + index.ToString());
                        //t.log("\t\t\t" + "civo.appVars[index] = " + civo.appVars[index].ToString());
                        break;

                    case "var to clipboard":
                        //index = int.Parse(commandItemNode.Attributes[1].Value.ToString());
                        //Clipboard.SetText(civo.appVars[index]);
                        break;

                    case "output var":
                        //index = int.Parse(commandItemNode.Attributes[1].Value.ToString());
                        break;

                    case "key":
                        civo.key          = commandItemNode.ChildNodes[0].InnerText.ToString();
                        civo.ctrlPressed  = DTools.intStringToBoolean(commandItemNode.Attributes[1].Value.ToString());
                        civo.altPressed   = DTools.intStringToBoolean(commandItemNode.Attributes[2].Value.ToString());
                        civo.shiftPressed = DTools.intStringToBoolean(commandItemNode.Attributes[3].Value.ToString());
                        break;

                    case "focus on application":
                        break;

                    case "delay":
                        t.log("\t\t\t" + "commandItemNode.Attributes[1].Value = " + commandItemNode.Attributes[1].Value.ToString());
                        civo.delayTime = float.Parse(commandItemNode.Attributes[1].Value);
                        break;
                    }


                    cvo.addCommandItem(civo);
                } // commandItemNode for loop end


                //t.log("\t----------------------------------");

                commands.Add(cvo);
            } // rootCommandNode for loop end
            t.log("------------------------------------------------------------");

            //Console.WriteLine(commands.ToString());

            fm.setStatus("Profile commands parsed...");

            fm.fmCommandListController.updateCommandListView();
        }
        // -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -


        // -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
        public void updateCommandListView()
        {
            t.log("FormCommandEditorListController.updateCommandListView");

            lvCommands.Clear();
            lvCommands.View      = View.Details;
            lvCommands.GridLines = true;
            //lvCommands.Sorting = SortOrder.Ascending;
            lvCommands.Columns.Add("No", 40, HorizontalAlignment.Left);
            lvCommands.Columns.Add("Command", 160, HorizontalAlignment.Left);

            if (fce.fceCommandManager.cvo.commandItems.Count > 14)
            {
                lvCommands.Columns.Add("Information", 200, HorizontalAlignment.Left);
            }
            else
            {
                lvCommands.Columns.Add("Information", 220, HorizontalAlignment.Left);
            }
            //lvCommands.HeaderStyle = ColumnHeaderStyle.None;
            //lvCommands.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.None);


            // fceCommandManager either holds a new CVO or a cloned CVO (any CVO work goes on there!)
            t.log("FormCommandEditorListController.updateCommandListView: commandItems.Count = " + fce.fceCommandManager.cvo.commandItems.Count);


            int count = 0;

            foreach (CommandItemVO civo in fce.fceCommandManager.cvo.commandItems)
            {
                count++;

                ListViewItem listViewItem;
                String       commandType = "";
                switch (civo.type)
                {
                case "clipboard":
                    commandType = "Insert text into clipboard";

                    //t.log("FormCommandEditorListController.updateCommandListView: " + civo.type);
                    listViewItem = new ListViewItem(count.ToString());
                    listViewItem.SubItems.Add(commandType);
                    listViewItem.SubItems.Add(DTools.stringCut(civo.clipboard, 28) + "...");
                    lvCommands.Items.Add(listViewItem);

                    break;


                case "key":
                    commandType = "Combination key";

                    //t.log("FormCommandEditorListController.updateCommandListView: " + civo.type);
                    listViewItem = new ListViewItem(count.ToString());
                    listViewItem.SubItems.Add(commandType);
                    listViewItem.SubItems.Add(civo.key);
                    lvCommands.Items.Add(listViewItem);

                    break;

                case "run application":
                    commandType = "Run application";

                    //t.log("FormCommandEditorListController.updateCommandListView: " + civo.type);
                    listViewItem = new ListViewItem(count.ToString());
                    listViewItem.SubItems.Add(commandType);
                    listViewItem.SubItems.Add(civo.applicationPath);
                    lvCommands.Items.Add(listViewItem);

                    break;
                }
            }
        }
Example #4
0
        // -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
        void speechRecognizedHandler(object sender, SpeechRecognizedEventArgs e)
        {
            //ui.log("Recognizer.speechRecognititionHandler()");
            //ui.setInputVolumeMetere(e.AudioLevel);
            //ui.log(e.Result.Confidence.ToString());

            // We dont process anything in the grammar to ignore!
            if (e.Result.Grammar.Name == "grammar to ignore")
            {
                return;
            }


            t.log("speechRecognizedHandler:  confidence = " + e.Result.Confidence + "    grammar = " + e.Result.Grammar.Name + "     Speech = " + e.Result.Text);


            Boolean like = DTools.StringQueryLike(e.Result.Text, hypothesizedSpeech);

            t.log("speechRecognizedHandler:  like = " + like);


            // Check that hypothesizedSpeech matches recognized speech
            if (!like)
            {
                t.log("speechRecognizedHandler:  REJECTED - Hypothesized speech and Recognized speech do not match or not alike!");
                return;
            }

            /*
             * if (hypothesizedSpeech != e.Result.Text)
             * {
             *  t.log("speechRecognizedHandler:  REJECTED - Hypothesized speech and Recognized speech do not math!");
             *  return;
             * }
             */


            Int16 conf = fm.getConfidenceLevel();

            String percent = Math.Round(Math.Round(e.Result.Confidence * 100)).ToString();
            Int16  p       = Int16.Parse(percent);

            if (p < conf)
            {
                t.log("speechRecognizedHandler:  REJECTED - Confidence level is below level set by the user! " + e.Result.Confidence + "/" + conf);
                return;
            }
            else
            {
                processingHypothesized = true;
                processAcceptedCommand(e.Result.Text);
            }



            /*
             *
             * if (e.Result.Grammar.Name == "grammar to ignore")
             * {
             *  t.log("speechRecognizedHandler: Rejecting speech command as it only matches grammar to ignore!");
             *  hypothesizedSpeech = "";
             *  hypothesizedConfidence = 0f;
             *  return;
             * }
             *
             * if (hypothesizedSpeech != e.Result.Text)
             * {
             *  t.log("speechRecognizedHandler: Rejecting speech command as hypothesized speech doesn't match recognized speech!");
             *  hypothesizedSpeech = "";
             *  hypothesizedConfidence = 0f;
             *  return;
             * }
             *
             * String percent = Math.Round(Math.Round(e.Result.Confidence * 100)).ToString();
             * Int16 p = Int16.Parse(percent);
             *
             *
             * //Console.WriteLine("speechRecognititionHandler(): e.Result.Grammar.Name = " + e.Result.Grammar.Name);
             * //Console.WriteLine("speechRecognititionHandler(): e.Result.Text = " + e.Result.Text);
             *
             * Int16 conf = fm.getConfidenceLevel();
             * commandCount++;
             *
             * if (p < conf)
             * {
             *  String msg = commandCount + ". command: \"" + e.Result.Text + "\"\n";
             *  msg += "COMMAND REJECTED with a " + percent + "% confidence level...";
             *  fm.setStatus(msg);
             *  //t.log("\n" + msg);
             * }
             * else
             * {
             *  String msg = commandCount + ". command: \"" + e.Result.Text + "\"\n";
             *  msg += "COMMAND ACCEPTED with a " + percent + "% confidence level!";
             *  fm.setStatus(msg);
             *  //t.log("\n" + msg);
             *
             *  fm.commandExecutionHandler.processCommand(e.Result.Text);
             * }
             *
             *
             * hypothesizedSpeech = "";
             * hypothesizedConfidence = 0f;
             */
        }