コード例 #1
0
        private void ProcessInput(string sRaw, string sInput, string scriptParamaters)
        {
            DataSet dsResults = new DataSet();

            try
            {
                if (wakeList.Contains(sInput) && gVRMuted == true)
                {
                    gVRMuted          = false;
                    lblStatus.Content = "I am awake.";
                }
                else if (sleepList.Contains(sInput) && gVRMuted == false)
                {
                    gVRMuted          = true;
                    lblStatus.Content = "I am sleeping. Zzzz";
                }
                else if (sleepList.Contains(sInput) && gVRMuted == true)
                {
                    return;
                }

                // gSpeechPlugin;
                string temp = OSAEObjectPropertyManager.GetObjectPropertyValue(gSpeechPlugin, "Speaking").Value.ToString().ToLower();

                if (temp.ToLower() == "false")
                {
                    if ((gVRMuted == false) || (sleepList.Contains(sInput)))
                    {
                        if (sInput.StartsWith("This is [OBJECT]"))
                        {
                            AddToLog("Heard: " + sRaw);
                            if (scriptParamaters != "")
                            {
                                if (gUser == scriptParamaters)
                                {
                                    return;
                                }
                                OSAEObject obj = OSAEObjectManager.GetObjectByName(scriptParamaters);
                                if (obj.Alias.Length > 0)
                                {
                                    gUser = obj.Alias;
                                }
                                else
                                {
                                    gUser = obj.Name;
                                }

                                AddToLog("I am talking to " + gUser);
                                lblObjectTalking.Content = "I am talking to " + gUser;
                                string sText = OSAEGrammar.SearchForMeaning(sInput, scriptParamaters, gUser);
                                return;
                            }
                        }

                        if (gUser == "")
                        {
                            AddToLog("I must know who I am talking with.");
                            //return;
                        }

                        try
                        {
                            string sLogEntry = "Heard: " + sRaw;
                            string sText     = OSAEGrammar.SearchForMeaning(sInput, scriptParamaters, gUser);

                            if (sText.Length > 0)
                            {
                                sLogEntry += ".  Ran: " + sText;
                                OSAEObjectPropertyManager.ObjectPropertySet(gUser, "Communication Method", "Speech", gUser);
                            }
                            AddToLog(sLogEntry);
                        }
                        catch {}
                    }
                }
            }
            catch (Exception ex)
            { AddToLog("Error in _SpeechRecognized: " + ex.Message); }
        }
コード例 #2
0
        private void oRecognizer_SpeechRecognized(object sender, System.Speech.Recognition.SpeechRecognizedEventArgs e)
        {
            try
            {
                RecognitionResult result          = e.Result;
                SemanticValue     semantics       = e.Result.Semantics;
                string            scriptParameter = "";
                if (e.Result.Semantics.ContainsKey("PARAM1"))
                {
                    string temp = e.Result.Semantics["PARAM1"].Value.ToString().Replace("'s", "").Replace("'S", "");
                    if (temp.ToUpper() == "I" || temp.ToUpper() == "ME" || temp.ToUpper() == "MY")
                    {
                        temp = gCurrentUser;
                    }
                    if (temp.ToUpper() == "YOU" || temp.ToUpper() == "YOUR")
                    {
                        temp = "SYSTEM";
                    }
                    scriptParameter = temp;
                    if (e.Result.Semantics.ContainsKey("PARAM2"))
                    {
                        temp = e.Result.Semantics["PARAM2"].Value.ToString().Replace("'s", "").Replace("'S", "");
                        if (temp.ToUpper() == "I" || temp.ToUpper() == "ME" || temp.ToUpper() == "MY")
                        {
                            temp = gCurrentUser;
                        }
                        if (temp.ToUpper() == "YOU" || temp.ToUpper() == "YOUR")
                        {
                            temp = "SYSTEM";
                        }
                        scriptParameter += "," + temp;
                        if (e.Result.Semantics.ContainsKey("PARAM3"))
                        {
                            temp = e.Result.Semantics["PARAM3"].Value.ToString().Replace("'s", "").Replace("'S", "");
                            if (temp.ToUpper() == "I" || temp.ToUpper() == "ME" || temp.ToUpper() == "MY")
                            {
                                temp = gCurrentUser;
                            }
                            if (temp.ToUpper() == "YOU" || temp.ToUpper() == "YOUR")
                            {
                                temp = "SYSTEM";
                            }
                            scriptParameter += "," + temp;
                        }
                    }
                }
                // scriptParameter = scriptParameter.Replace();
                string sResults = "";
                if (e.Result.Semantics.ContainsKey("ANSWER"))
                {
                    Question_Answered(e.Result.Semantics["ANSWER"].Value.ToString());
                }
                else
                {
                    if (result.Grammar.Name.ToString() == "Direct Match")
                    {
                        Log.Debug("Searching for: " + sResults);
                        sResults = OSAEGrammar.SearchForMeaning(result.Text, scriptParameter, gCurrentUser);
                    }
                    else
                    {
                        Log.Debug("Searching for: " + sResults);
                        sResults = OSAEGrammar.SearchForMeaning(result.Grammar.Name.ToString(), scriptParameter, gCurrentUser);
                    }
                }

                Log.Info("Search Results: " + sResults);
            }
            catch (Exception ex)
            { Log.Error("Error in _SpeechRecognized!", ex); }
        }
コード例 #3
0
        private void ProcessInput(string sRaw, string sInput, string scriptParamaters)
        {
            DataSet dsResults = new DataSet();

            try
            {
                if (wakeList.Contains(sInput) && gVRMuted == true)
                {
                    gVRMuted          = false;
                    lblStatus.Content = "I am awake.";
                }
                else if (sleepList.Contains(sInput) && gVRMuted == false)
                {
                    gVRMuted          = true;
                    lblStatus.Content = "I am sleeping. Zzzz";
                }
                else if (sleepList.Contains(sInput) && gVRMuted == true)
                {
                    return;
                }

                if (sInput.StartsWith("This is [OBJECT]"))
                {
                    AddToLog("Heard: " + sRaw);
                    if (scriptParamaters != "")
                    {
                        gUser = scriptParamaters;
                        AddToLog("I am talking to " + gUser);
                        lblObjectTalking.Content = "I am talking to " + gUser;

                        string sText = OSAEGrammar.SearchForMeaning(sInput, scriptParamaters, gUser);
                        oRecognizer.UnloadAllGrammars();
                        oRecognizer = OSAEGrammar.Load_Direct_Grammar(oRecognizer);
                        oRecognizer = OSAEGrammar.Load_OSA_Grammar(oRecognizer);
                        SaveGrammars();
                    }
                }

                // gSpeechPlugin;
                String temp = OSAEObjectPropertyManager.GetObjectPropertyValue(gSpeechPlugin, "Speaking").Value.ToString().ToLower();

                if (temp.ToLower() == "false")
                {
                    if ((gVRMuted == false) || (sleepList.Contains(sInput)))
                    {
                        try
                        {
                            string sLogEntry = "Heard: " + sRaw;
                            //string sText = OSAE.Common.MatchPattern(sInput,gUser);
                            //string sText = MatchPattern(sInput,gUser);
                            string sText = OSAEGrammar.SearchForMeaning(sInput, scriptParamaters, gUser);

                            if (sText.Length > 0)
                            {
                                sLogEntry += ".  Ran: " + sText;
                            }
                            OSAEObjectPropertyManager.ObjectPropertySet(gUser, "Communication Method", "Speech", gUser);
                            AddToLog(sLogEntry);
                        }
                        catch {}
                    }
                }
            }
            catch (Exception ex)
            { AddToLog("Error in _SpeechRecognized: " + ex.Message); }
        }