private void ListenForInput()
        {
            try {
                // try to restore saved state after reloading the configuration file.
                consoleInput.RestoreSavedState();

                while (true)
                {
                    string input = consoleInput.ReadLine();

                    // input will be null when Skyrim terminated (stdin closed)
                    if (input == null)
                    {
                        config.Stop();
                        break;
                    }

                    Trace.TraceInformation("Received command: {0}", input);
                    lock (dialogueLock) {
                        string[] tokens  = input.Split('|');
                        string   command = tokens[0];
                        if (command.Equals("START_DIALOGUE"))
                        {
                            consoleInput.currentDialogue = input;
                            if (dialogueEnabled)
                            {
                                currentDialogue = DialogueList.Parse(string.Join("|", tokens, 1, tokens.Length - 1), config);
                                // Switch to dialogue mode
                                recognizer.StartSpeechRecognition(true, currentDialogue);
                            }
                            else
                            {
                                Trace.TraceInformation("Dialogue was disabled, pause the speech recognition");
                                recognizer.StopRecognition();
                            }
                        }
                        else if (command.Equals("STOP_DIALOGUE"))
                        {
                            // Switch to command mode
                            recognizer.StartSpeechRecognition(false, config.GetConsoleCommandList(), favoritesList);
                            currentDialogue = null;
                            consoleInput.currentDialogue = null;
                        }
                        else if (command.Equals("FAVORITES"))
                        {
                            consoleInput.currentFavoritesList = input;
                            favoritesList.Update(string.Join("|", tokens, 1, tokens.Length - 1));
                            if (consoleInput.currentDialogue == null)
                            {
                                recognizer.StartSpeechRecognition(false, config.GetConsoleCommandList(), favoritesList);
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Trace.TraceError(ex.ToString());
            }
        }
        private static void ListenForInput()
        {
            try {
                while (true)
                {
                    string input = Console.ReadLine();

                    // input will be null when Skyrim is terminated
                    if (input == null)
                    {
                        Trace.TraceInformation("Skyrim is terminated, recognition service will quit.");
                        break;
                    }

                    Trace.TraceInformation("Received command: {0}", input);

                    string[] tokens  = input.Split('|');
                    string   command = tokens[0];
                    if (command.Equals("START_DIALOGUE"))
                    {
                        lock (dialogueLock) {
                            currentDialogue = DialogueList.Parse(string.Join("|", tokens, 1, tokens.Length - 1));
                        }
                        // Switch to dialogue mode
                        recognizer.StartSpeechRecognition(true, currentDialogue);
                    }
                    else if (command.Equals("STOP_DIALOGUE"))
                    {
                        // Switch to command mode
                        recognizer.StartSpeechRecognition(false, Configuration.GetConsoleCommandList(), favoritesList);
                        lock (dialogueLock) {
                            currentDialogue = null;
                        }
                    }
                    else if (command.Equals("FAVORITES"))
                    {
                        favoritesList.Update(string.Join("|", tokens, 1, tokens.Length - 1));
                        if (currentDialogue == null)
                        {
                            recognizer.StartSpeechRecognition(false, Configuration.GetConsoleCommandList(), favoritesList);
                        }
                    }
                }
            } catch (Exception ex) {
                Trace.TraceError(ex.ToString());
            }
        }
Ejemplo n.º 3
0
        private void ListenForInput()
        {
            try {
                // try to restore saved state after reloading the configuration file.
                consoleInput.RestoreSavedState();

                while (true)
                {
                    string input = consoleInput.ReadLine();

                    // input will be null when Skyrim terminated (stdin closed)
                    if (input == null)
                    {
                        break;
                    }

                    Trace.TraceInformation("Received command: {0}", input);

                    string[] tokens  = input.Split('|');
                    string   command = tokens[0];

                    if (command.Equals("START_DIALOGUE"))
                    {
                        // Switch to dialogue mode
                        consoleInput.currentDialogue = input;
                        lock (dialogueLock) {
                            currentDialogue = DialogueList.Parse(string.Join("|", tokens, 1, tokens.Length - 1), config);
                        }
                    }
                    else if (command.Equals("STOP_DIALOGUE"))
                    {
                        consoleInput.currentDialogue = null;
                        // Switch to command mode
                        lock (dialogueLock) {
                            currentDialogue = null;
                        }
                    }
                    else if (command.Equals("FAVORITES"))
                    {
                        consoleInput.currentFavoritesList = input;
                        favoritesList.Update(string.Join("|", tokens, 1, tokens.Length - 1));
                    }
                    else if (command.Equals("SPELLBOOK"))
                    {
                        spellBook.UpdateSpells(tokens.Skip(1));
                    }
                    else if (command.Equals("SHOUTS"))
                    {
                        shoutsKnowledge.UpdateShouts(tokens.Skip(1));
                    }
                    else if (command.Equals("GAMESTATE"))
                    {
                        GameState newState;
                        newState.currentMenu   = tokens[1];
                        newState.isInCombat    = tokens[2].Equals("1");
                        newState.isWeaponDrawn = tokens[3].Equals("1");
                        newState.isSneaking    = tokens[4].Equals("1");

                        recognizer.SetGameState(newState);
                    }


                    if (currentDialogue != null)
                    {
                        recognizer.StartSpeechRecognition(true, currentDialogue);
                    }
                    else
                    {
                        recognizer.StartSpeechRecognition(false, commandList, favoritesList, spellBook, shoutsKnowledge);
                    }
                }
            } catch (Exception ex) {
                Trace.TraceError(ex.ToString());
            }
        }