Esempio n. 1
0
 // Initialization
 public jarvis()
 {
     recognizer = new SpeechRecognitionEngine();
     dictationGrammar = new DictationGrammar();
     recognizer.LoadGrammar(dictationGrammar);
     recognizer.SetInputToDefaultAudioDevice();
     synthesizer = new SpeechSynthesizer();
     lexicon = (PhraseTrie) FileOperations.FileToObject(lexPath);
     if (lexicon == null)
     {
         lexicon = new PhraseTrie();
     }
     responseGraph = (PhraseGraph) FileOperations.FileToObject(resPath);
     if (responseGraph == null)
     {
         responseGraph = new PhraseGraph("");
     }
     responseNode = responseGraph.getHead();
 }
Esempio n. 2
0
 // Listens for phrases to start the recognition system
 private void recognition()
 {
     try
     {
         RecognitionResult result = recognizer.Recognize();
         Console.Out.WriteLine("Recognition Heard: " + result.Text);
         String text = result.Text;
         //String text = Console.ReadLine();
         if (beginCommand(text))
         {
             this.responseNode = responseGraph.getHead();
             this.synthesis("I am listening");
             this.command();
         }
     }
     catch (NullReferenceException e)
     {
     }
 }
Esempio n. 3
0
        // Determines if the result is valid and if so performs the desired action
        private void parseResult(String text)
        {
            // Taking care of any action required
            ActionInterface action = (ActionInterface)lexicon.getAction(text);
            if (action != null)
            {
                action.run(this);
            }
            else
            {
                Console.Out.WriteLine("No Action Found");
            }

            // Taking care of the response
            PhraseGraph.PhraseNode response = responseNode.getClosestResponse(text);
            if (response != null)
            {
                responseGraph.add(text, responseNode);
                String responseText = response.getPhrase();
                Console.Out.WriteLine("Jarvis: {0}", responseText);
                this.synthesis(responseText);
                responseNode = response;
            }
            else
            {
                response = responseGraph.add(text, responseNode);
                String responseText = response.getPhrase();
                //Console.Out.WriteLine("Adding: {0}", responseText);
                this.synthesis(responseText);
                responseNode = response;
            }
        }