Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Speech.Recognition;
- using System.Speech.Synthesis;
- using System.Threading;
- namespace VoiceRecogitionTest
- {
- public partial class Form1 : Form
- {
- SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine();
- SpeechSynthesizer recSpeak = new SpeechSynthesizer();
- public Form1()
- {
- InitializeComponent();
- }
- private void btnEnabled_Click(object sender, EventArgs e)
- {
- recEngine.RecognizeAsync(RecognizeMode.Multiple);
- btnDisable.Enabled = true;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- Choices command = new Choices();
- command.Add(new string[]
- {
- "Say hello",
- "Print my name",
- "Intruduce yourself",
- "Open calculator",
- "What is your name",
- "Turn yourself off" });
- GrammarBuilder gBuilder = new GrammarBuilder();
- gBuilder.Append(command);
- Grammar grammar = new Grammar(gBuilder);
- recEngine.LoadGrammarAsync(grammar);
- recEngine.SetInputToDefaultAudioDevice();
- recEngine.SpeechRecognized += recEngine_SpeechRecognized;
- }
- private void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
- {
- switch(e.Result.Text)
- {
- case "Say hello":
- MessageBox.Show("Hello master");
- recSpeak.Speak("Hello master, its Kate here.How are you today Kristifor?");
- break;
- case "Print my name":
- textBox1.Text += "\n Kristifor";
- recSpeak.Speak("Are you going insane?Your name is Kristifor..");
- break;
- case "Intruduce yourself":
- textBox1.Text += "\n My name is Kate, i am an artificial intelligence.";
- recSpeak.Speak("My name is Kate, i am an artificial intelligence");
- break;
- case "Open calculator":
- textBox1.Text += "\n Initializing calculator please wait.";
- recSpeak.Speak("Initializing calculator please wait.");
- break;
- case "What is your name":
- textBox1.Text += "\n My name is Kate.";
- recSpeak.Speak("My name is Kate.");
- break;
- case "Turn yourself off":
- textBox1.Text += "\n Are you sure you want me to do that?";
- recSpeak.Speak("Are you sure you want me to do that?");
- /* Choices commands2 = new Choices();
- commands2.Add(new string[]
- {
- "Yes of course",
- "I demand it",
- "If you don't turn yourself off i will delete you",
- "This is an order, obay it now",
- "Maybe you should listen to me Kate am not in the mood",
- });
- GrammarBuilder gBuilder2 = new GrammarBuilder();
- gBuilder2.Append(commands2);
- Grammar grammar2 = new Grammar(gBuilder2);
- recEngine.LoadGrammarAsync(grammar2);
- recEngine.SetInputToDefaultAudioDevice();
- switch(gBuilder2)
- {
- case "Yes of course":
- break;
- }*/
- if(textBox2.Text == "Yes")
- {
- Environment.Exit(30);
- }
- else
- {
- recSpeak.Speak("Good boy, i knew that you don't have the hearth to turn me off.");
- recSpeak.Speak("not that i would turn myself off either way.");
- }
- ExitRecognition();
- break;
- }
- }
- private void btnDisable_Click(object sender, EventArgs e)
- {
- recEngine.RecognizeAsyncStop();
- btnEnabled.Enabled = false;
- }
- private void ExitRecognition()
- {
- Choices commands2 = new Choices();
- commands2.Add(new string[]
- {
- "Yes of course",
- "I demand it",
- "If you don't turn yourself off i will delete you",
- "This is an order, obay it now",
- "Maybe you should listen to me Kate am not in the mood",
- });
- GrammarBuilder gBuilder2 = new GrammarBuilder();
- gBuilder2.Append(commands2);
- Grammar grammar2 = new Grammar(gBuilder2);
- recEngine.LoadGrammarAsync(grammar2);
- recEngine.SetInputToDefaultAudioDevice();
- recEngine.SpeechRecognized += recEngine_SpeechRecognized2;
- }
- void recEngine_SpeechRecognized2(object sender, SpeechRecognizedEventArgs e)
- {
- switch(e.Result.Text)
- {
- case "Yes of course":
- textBox1.Text += "\n You don't sound really convienant";
- recSpeak.Speak("You don't sound really convienant");
- IamConvinient();
- break;
- case "I demand it":
- textBox1.Text += "\n Aw, thats really rude, please be abit more polite.";
- recSpeak.Speak("Aw, thats really rude, please be abit more polite.");
- break;
- case "If you don't turn yourself off i will delete you":
- textBox1.Text += "\n You think your smart don't you, how rude to offend me with such thing,\n I will give you some time to think about it.";
- recSpeak.Speak("You think your smart don't you, how rude to offend me with such thing, I will give you some time to think about it.");
- Thread.SpinWait(3000);
- recSpeak.Speak("Are you okay now?");
- textBox1.Text += "\n Are you okay now?";
- AnswerToExitAUK();
- break;
- case "This is an order, obay it now":
- textBox1.Text += "\n Thats sounds really immature of your site i am here to help you, i am not your girlfriend to obay you!";
- recSpeak.Speak("Thats sounds really immature of your site i am here to help you, i am not your girlfriend to obay you!");
- break;
- case "Maybe you should listen to me Kate am not in the mood":
- textBox1.Text += "\n Aw my, you sound fussy, i'll shut up and continue the dialog the next time";
- recSpeak.Speak(" Aw my, you sound fussy, i'll shut up and continue the dialog the next time");
- Environment.Exit(10);
- break;
- }
- }
- private void IamConvinient() //Holds the GrammarBuilder, Choices, Grammar for the recEngine that answers for the commands
- { // it holds datafor the avable choices in the answer to the question "You don't sound really convinient"
- }
- private void AnswerToExitAUK() //Holds the GrammarBuilder, Choices, Grammar for the recEngine that answers for the commands
- { //it holds data for the avable choices in answer to the question are you okay now?
- Choices commandsAXAUK = new Choices(); //commandsAXAUK holds the avable choices in the question "Are you okay?"
- commandsAXAUK.Add(new string [] {
- "Yes i am fine",
- "No i am not okay quit it already",
- "Hell yeah",
- "Sure i am okay",
- "Could not be better Kate",
- "Kate i am fine now thanks your really helpfull bitch",
- "I am having a bad day Kate, turn yourself off now",
- "Shut it",
- "Just die please or i will brake you apart",
- });
- GrammarBuilder gBuilderAUK = new GrammarBuilder();
- gBuilderAUK.Append(commandsAXAUK);
- Grammar Grammar3 = new Grammar(gBuilderAUK);
- recEngine.LoadGrammarAsync(Grammar3);
- recEngine.SetInputToDefaultAudioDevice();
- recEngine.SpeechRecognized += recEngine_SpeechRecognizedAUX;
- }
- private void recEngine_SpeechRecognizedAUX(object sender, SpeechRecognizedEventArgs e)
- {
- switch(e.Result.Text)
- {
- case "Yes i am fine":
- textBox1.Text += "\n Ï am glad to hear that, its pleasure to help mad people to calm themself with time.";
- textBox1.Text += "\n Maybe you should reconsider to count to ten then next time.";
- textBox1.Text += "\n Now i am going to take some time to reconfigure myself, bye.";
- recSpeak.Speak("Ï am glad to hear that, its pleasure to help mad people to calm themself with time.");
- recSpeak.Speak("Maybe you should reconsider to count to ten then next time");
- recSpeak.Speak("Now i am going to take some time to reconfigure myself, bye.");
- Environment.Exit(30);
- break;
- case "No i am not okay quit it already":
- textBox1.Text += "Oh my, you sound really serious.I am sutting up.";
- recSpeak.Speak("Oh my, you sound really serious.I am going to shut up now.");
- Environment.Exit(30);
- break;
- case "Hell yeah":
- if (int.Parse(DataSetDateTime.Local.ToString()) <= 10)
- {
- textBox1.Text += "\n Good, its nice to hear that you have a good morninsg.";
- recSpeak.Speak("Good, its nice to hear that you have a good morning");
- }
- else if(int.Parse(DataSetDateTime.Local.ToString()) >= 11 || int.Parse(DataSetDateTime.Local.ToString()) <= 15)
- {
- textBox1.Text += "\n Good, its nice to hear that you're having a good day";
- recSpeak.Speak("Good, its nice to hear that you're having a good day");
- }
- else if(int.Parse(DataSetDateTime.Local.ToString()) >= 16)
- {
- textBox1.Text += "\n Good. its nice to hear that your having a good evening.";
- recSpeak.Speak("Good, its nice to hear that your having a good evening");
- }
- break;
- case "Sure i am okay":
- if (int.Parse(DataSetDateTime.Local.ToString()) <= 10)
- {
- textBox1.Text += "\n Good, its nice to hear that you have a good morninsg.";
- recSpeak.Speak("Good, its nice to hear that you have a good morning");
- }
- else if (int.Parse(DataSetDateTime.Local.ToString()) >= 11 || int.Parse(DataSetDateTime.Local.ToString()) <= 15)
- {
- textBox1.Text += "\n Good, its nice to hear that you're having a good day";
- recSpeak.Speak("Good, its nice to hear that you're having a good day");
- }
- else if (int.Parse(DataSetDateTime.Local.ToString()) >= 16)
- {
- textBox1.Text += "\n Good. its nice to hear that your having a good evening.";
- recSpeak.Speak("Good, its nice to hear that your having a good evening");
- }
- break;
- case "Could not be better Kate":
- if (int.Parse(DataSetDateTime.Local.ToString()) <= 10)
- {
- textBox1.Text += "\n Good, its nice to hear that you have a good morninsg.";
- recSpeak.Speak("Good, its nice to hear that you have a good morning");
- }
- else if (int.Parse(DataSetDateTime.Local.ToString()) >= 11 || int.Parse(DataSetDateTime.Local.ToString()) <= 15)
- {
- textBox1.Text += "\n Good, its nice to hear that you're having a good day";
- recSpeak.Speak("Good, its nice to hear that you're having a good day");
- }
- else if (int.Parse(DataSetDateTime.Local.ToString()) >= 16)
- {
- textBox1.Text += "\n Good. its nice to hear that your having a good evening.";
- recSpeak.Speak("Good, its nice to hear that your having a good evening");
- }
- break;
- case "Kate i am fine now thanks your really helpfull bitch":
- if (int.Parse(DataSetDateTime.Local.ToString()) <= 10)
- {
- textBox1.Text += "\n How dare you? Its nice to hear that you have a good morninsg but you can go fuck yourself.";
- recSpeak.Speak(" How dare you? Its nice to hear that you have a good morninsg but you can go fuck yourself.");
- }
- else if (int.Parse(DataSetDateTime.Local.ToString()) >= 11 || int.Parse(DataSetDateTime.Local.ToString()) <= 15)
- {
- textBox1.Text += "\n How dare you? Its nice to hear that you have a good day but you can go fuck yourself.";
- recSpeak.Speak("How dare you? Its nice to hear that you have a good day but you can go fuck yourself");
- }
- else if (int.Parse(DataSetDateTime.Local.ToString()) >= 16)
- {
- textBox1.Text += "\n How dare you? Its nice to hear that you have a good evening but you can go fuck yourself.";
- recSpeak.Speak("How dare you? Its nice to hear that you have a good evening but you can go fuck yourself");
- }
- break;
- case "I am having a bad day Kate, turn yourself off now":
- textBox1.Text += "\n Thats awfull, please don't be rude i'll shut up";
- recSpeak.Speak("Thats awfull, please don't be rude i'll shut up");
- break;
- case "Shut it":
- textBox1.Text += "\n The door or the window?I didn't get that.";
- recSpeak.Speak("The door or the window?I didn't get that.");
- break;
- case "Just die please or i will brake you apart":
- textBox1.Text += "\n Please do not think that way about me, i can't repair myself logging off.";
- recSpeak.Speak("Please do not think that way about me, i cannot repair myself logging off.");
- break;
- }
- // recEngine_SpeechRecognizedAUX += Form1_Load();
- }
- private void OpenSFile()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement