using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Speech.Recognition; using System.Speech.Synthesis; using System.IO; namespace JARVIStest { public partial class Form1 : Form { SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine(); SpeechSynthesizer JARVIS = new SpeechSynthesizer(); string QEvent; int count = 1; Random rnd = new Random(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { _recognizer.SetInputToDefaultAudioDevice(); _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Users\Cpyros\Desktop\lefteris\Commands.txt"))))); _recognizer.SpeechRecognized += new EventHandler<speechrecognizedeventargs>(_recognizer_SpeechRecognized); _recognizer.RecognizeAsync(RecognizeMode.Multiple); } void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { int ranNum = rnd.Next(1, 10); string speech = e.Result.Text; switch (speech) { //GREETINGS case "hello": case "hello jarvis": if (ranNum < 6) { JARVIS.Speak("Hello sir"); } else if (ranNum > 5) { JARVIS.Speak("Hi"); } break; case "goodbye": case "goodbye jarvis": case "close": case "close jarvis": JARVIS.Speak("Until next time"); Close(); break; case "jarvis": if (ranNum < 5) { QEvent = ""; JARVIS.Speak("Yes sir"); } else if (ranNum > 4) { QEvent = ""; JARVIS.Speak("Yes?"); } break;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)