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.Diagnostics;
- using NAudio.CoreAudioApi;
- namespace Monica
- {
- public partial class Form1 : Form
- {
- SpeechSynthesizer s = new SpeechSynthesizer();
- Choices commands = new Choices();
- public Form1()
- {
- InitializeComponent();
- MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
- var devices = enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
- comboBox2.Items.AddRange(devices.ToArray());
- var microphones = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);
- comboBox1.Items.AddRange(microphones.ToArray());
- }
- private void logs_Label_Click(object sender, EventArgs e)
- {
- }
- SpeechRecognitionEngine rec = new SpeechRecognitionEngine();
- private void btn_Enabled_Click(object sender, EventArgs e)
- {
- btn_Enabled.Enabled = false;
- btn_Disabled.Enabled = true;
- rec.SpeechRecognized += rec_VorbireRecunoscuta;
- }
- private void btn_Disabled_Click(object sender, EventArgs e)
- {
- btn_Disabled.Enabled = false;
- btn_Enabled.Enabled = true;
- rec.SpeechRecognized -= rec_VorbireRecunoscuta;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- MessageBox.Show("Made by Murjan Andrei. \n \n" +
- "Small helper: Daca nu folositi modul de speech recognition si doriti sa introduceti comenzile manual, folositi casuta de text 'Insert command' pentru a face acest lucru. Insa, de retinut este faptul ca nu toate comenzile functioneaza pe modul manual de introducere al acestora. Iata toate comenzile care nu functioneaza in modul manual: \n \n" +
- "hide \n" +
- "show \n" +
- "maximize \n" +
- "play \n" +
- "pause \n" +
- "forward \n" +
- "rewind \n" +
- "youtube fullscreen \n" +
- "disable voice recognition [Nu butonul, ci comanda inserata]", "Monica A.I. Assistant", MessageBoxButtons.OK, MessageBoxIcon.Information);
- commands.Add(new String[] { "hello",
- "hey",
- "hi",
- "how are you",
- "stop talking",
- "wait",
- "resume",
- "what's up",
- "i want to play a game",
- "blue",
- "yellow",
- "green",
- "red",
- "i don't know",
- "monica",
- "thank you",
- "thanks",
- "what's your name",
- "tell me a joke",
- "what's your story",
- "hide",
- "show",
- "now",
- "what's today",
- "what's the time",
- "what's the weather like",
- "lock computer",
- "minimize",
- "maximize",
- "open program",
- "open gmail",
- "open google drive",
- "open browser",
- "open youtube",
- "open yahoo mail",
- "open visual studio",
- "search on google",
- "search on youtube",
- "play",
- "pause",
- "forward",
- "rewind",
- "youtube fullscreen",
- "disable voice recognition",
- "dotto",
- "goodbye"});
- Grammar gr = new Grammar(new GrammarBuilder(commands));
- try
- {
- rec.RequestRecognizerUpdate();
- rec.LoadGrammar(gr);
- rec.SetInputToDefaultAudioDevice();
- rec.RecognizeAsync(RecognizeMode.Multiple);
- }
- catch
- {
- return;
- }
- }
- public void Vorbeste(PromptBuilder pB, String h)
- {
- pB = new PromptBuilder();
- pB.StartSentence();
- pB.AppendText(h, PromptEmphasis.Moderate);
- pB.EndSentence();
- SpeechSynthesizer s = new SpeechSynthesizer();
- s.SelectVoice("Microsoft Zira Desktop");
- s.Rate = 0;
- s.Volume = 100;
- s.SpeakAsync(pB);
- logs_Text.AppendText(h + "\n");
- }
- public void VorbesteSync(PromptBuilder pB, String h)
- {
- pB = new PromptBuilder();
- pB.StartSentence();
- pB.AppendText(h, PromptEmphasis.Moderate);
- pB.EndSentence();
- SpeechSynthesizer s = new SpeechSynthesizer();
- s.SelectVoice("Microsoft Zira Desktop");
- s.Rate = 0;
- s.Volume = 100;
- s.Speak(pB);
- logs_Text.AppendText(h + "\n");
- }
- public String Greetings()
- {
- Random r = new Random();
- String[] greets = new String[6] { "Hey!", "Hi there!", "Howdy!", "Hi!", "Hello!", "Welcome back." };
- return greets[r.Next(0, 6)];
- }
- public String Mood()
- {
- Random r = new Random();
- String[] moods = new String[7] { "I'm fine! How about you?", "Feeling awesome!", "I'm ok.", "Could be better.", "Excited to help you!", "I'm sleepy... How about you?", "I'm a bot, I don't have moods... Often." };
- return moods[r.Next(0, 7)];
- }
- public String AvailableGames()
- {
- Random r = new Random();
- String[] moods = new String[3] { "Simon Says", "Guess my number", "Rock, Paper, Scissors"};
- return moods[r.Next(0, 3)];
- }
- public String Monica()
- {
- Random r = new Random();
- String[] answer = new String[4] { "That's me! What's up?", "Yes?", "Here to help you!", "Awaiting commands." };
- return answer[r.Next(0, 4)];
- }
- public String Joke()
- {
- Random r = new Random();
- String[] jokes = new String[18] { "Why did the robot cross the road? It was programmed by the chicken.",
- "A robot walks into a bar, orders a drink, and lays down some cash. Bartender says, Hey, we don't serve robots. And the robot says, 'Oh, but someday you will.'",
- "Why do robots have summer holidays? To recharge their batteries.",
- "I got myself a new robot puppy. Dogmatic.",
- "What is a robot’s favourite genre of music? Heavy metal.",
- "Why did the robot go back to school? He was getting a bit rusty.",
- "What sort of robot turns into a tractor? A transfarmer.",
- "What does R2D2 use to open PDF files? Adobe Wan Kenobi.",
- "Why was the robot bankrupt? He had used all his cache.",
- "Why is a robot mechanic never lonely? Because he’s always making new friends.",
- "A rabbi, an Arab, a robot, and a Catholic priest walk into a bar. Only the robot exits.",
- "A robot walks into a pharmacy. The pharmacist asks him if he’d like anything. The robot replies, 'A soul.'",
- "How do you stop a robot from destroying you and the rest of civilization? You don’t.",
- "Knock knock. Who’s there? A robot. Oh, shit.",
- "What’s a robot’s favorite cereal? Robos. NOTE: Robos are made of the tears of human children.",
- "Little Susie tosses a clock out the window. A robot inquires, 'Why did you do that?' She replies, 'I wanted to see time fly!' The robot says, 'Ah... A perfect subject for elimination', and shoots her with a laser beam through the face.",
- "Why was six afraid of seven? Because seven was a robot.",
- "How many robots does it take to screw in a light bulb? Three... one to hold the bulb, and two to turn the ladder!"};
- return jokes[r.Next(0, 18)];
- }
- public String Plans()
- {
- Random r = new Random();
- String[] plans = new String[7] { "The 'Close application' button.", "Not much.", "Counting some cache. I have to know how much memory I'm using while helping you.", "Defragmenting my room.", "Talking to you, dummy.", "Just relaxing a bit, while waiting for your commands.", "Browsing Facebook." };
- return plans[r.Next(0, 7)];
- }
- public String Story()
- {
- Random r = new Random();
- String[] stories = new String[3] { "Ok, fine, I'll tell you. When I was first created, I was just an empty form application. No buttons. No text boxes. No nothing. But now, with the help of you, I am a fully functional A.I. Assistant, ready to make your job easier.",
- "Ask Wall-E or Cortana for that, I'm not telling you anything.",
- "La la la la la la la la... la. By that, I meant that there is nothing to be said."};
- return stories[r.Next(0, 3)];
- }
- public String Welcome()
- {
- Random r = new Random();
- String[] welcomes = new String[5] {"You're welcome!", "No problem!", "Just doing my job.", "Kisses.", "My pleasure!" };
- return welcomes[r.Next(0, 5)];
- }
- public void SimonSays(String r)
- {
- Random randomColour = new Random();
- PromptBuilder pB = new PromptBuilder();
- String[] colours = new String[4] { "blue ", "yellow ", "green ", "red " };
- String mmrz1, mmrz2, mmrz3, mmrz4, mmrz5, mmrz6, mmrz7, mmrz8, mmrz9, mmrz10;
- Int32 score = 0;
- mmrz1 = colours[randomColour.Next(0, 4)];
- mmrz2 = colours[randomColour.Next(0, 4)] + mmrz1;
- mmrz3 = colours[randomColour.Next(0, 4)] + mmrz2;
- mmrz4 = colours[randomColour.Next(0, 4)] + mmrz3;
- mmrz5 = colours[randomColour.Next(0, 4)] + mmrz4;
- mmrz6 = colours[randomColour.Next(0, 4)] + mmrz5;
- mmrz7 = colours[randomColour.Next(0, 4)] + mmrz6;
- mmrz8 = colours[randomColour.Next(0, 4)] + mmrz7;
- mmrz9 = colours[randomColour.Next(0, 4)] + mmrz8;
- mmrz10 = colours[randomColour.Next(0, 4)] + mmrz9;
- VorbesteSync(pB, "In this game, you need to memorize the colour said by me, and then repeat it. Maximum score to reach: 10");
- Vorbeste(pB, "Simon says: " + mmrz1);
- if(r == "i don't know")
- {
- Vorbeste(pB, "Too bad. You lose. Your score: " + score.ToString());
- return;
- }
- if (r == mmrz1)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "Adding colour to sequence...");
- Vorbeste(pB, "Simon says: " + mmrz2);
- if (r == mmrz2)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "Adding colour to sequence...");
- Vorbeste(pB, "Simon says: " + mmrz3);
- if (r == mmrz3)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "Adding colour to sequence...");
- Vorbeste(pB, "Simon says: " + mmrz4);
- if (r == mmrz4)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "Adding colour to sequence...");
- Vorbeste(pB, "Simon says: " + mmrz5);
- if (r == mmrz5)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "Adding colour to sequence...");
- Vorbeste(pB, "Simon says: " + mmrz6);
- if (r == mmrz6)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "Adding colour to sequence...");
- Vorbeste(pB, "Simon says: " + mmrz7);
- if (r == mmrz7)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "Adding colour to sequence...");
- Vorbeste(pB, "Simon says: " + mmrz8);
- if (r == mmrz8)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "Adding colour to sequence...");
- Vorbeste(pB, "Simon says: " + mmrz9);
- if (r == mmrz9)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "Adding colour to sequence...");
- Vorbeste(pB, "Simon says: " + mmrz10);
- if (r == mmrz2)
- {
- score++;
- Vorbeste(pB, "Correct. Current score: " + score.ToString() + "You win! Congratulations.");
- return;
- }
- else
- {
- Vorbeste(pB, "Incorrect. You lose. Your score: " + score.ToString());
- return;
- }
- }
- else
- {
- Vorbeste(pB, "Incorrect. You lose. Your score: " + score.ToString());
- return;
- }
- }
- else
- {
- Vorbeste(pB, "Incorrect. You lose. Your score: " + score.ToString());
- return;
- }
- }
- else
- {
- Vorbeste(pB, "Incorrect. You lose. Your score: " + score.ToString());
- return;
- }
- }
- else
- {
- Vorbeste(pB, "Incorrect. You lose. Your score: " + score.ToString());
- return;
- }
- }
- else
- {
- Vorbeste(pB, "Incorrect. You lose. Your score: " + score.ToString());
- return;
- }
- }
- else
- {
- Vorbeste(pB, "Incorrect. You lose. Your score: " + score.ToString());
- return;
- }
- }
- else
- {
- Vorbeste(pB, "Incorrect. You lose. Your score: " + score.ToString());
- return;
- }
- }
- else
- {
- Vorbeste(pB, "Incorrect. You lose. Your score: " + score.ToString());
- return;
- }
- }
- }
- private void rec_VorbireRecunoscuta(object sender, SpeechRecognizedEventArgs e)
- {
- PromptBuilder pB = new PromptBuilder();
- String r = e.Result.Text;
- switch(r)
- {
- case "hello":
- case "hi":
- case "hey":
- Vorbeste(pB, Greetings());
- break;
- case "how are you":
- Vorbeste(pB, Mood());
- break;
- case "what's up":
- Vorbeste(pB, Plans());
- break;
- case "thank you":
- case "thanks":
- Vorbeste(pB, Welcome());
- break;
- case "monica":
- Vorbeste(pB, Monica());
- break;
- case "i want to play a game":
- VorbesteSync(pB, "Ok. Initializing game components...");
- VorbesteSync(pB, "The available games are: 'Rock Paper Scissors', 'Simon Says' and 'Guess my number'...");
- VorbesteSync(pB, "Selecting one randomly...");
- switch(AvailableGames())
- {
- case "Simon Says":
- VorbesteSync(pB, "Active game: Simon Says");
- if (r == "stop game")
- return;
- SimonSays(r);
- break;
- case "Guess my number":
- VorbesteSync(pB, "Active game: Guess my number");
- break;
- case "Rock, Paper, Scissors":
- VorbesteSync(pB, "Active game: Rock Paper Scissors");
- break;
- }
- break;
- case "what's your name":
- Vorbeste(pB, "My name is Monica! I am an A.I. assistant that makes your job easier when it comes to using your computer.");
- break;
- case "tell me a joke":
- Vorbeste(pB, Joke());
- break;
- case "what's your story":
- Vorbeste(pB, Story());
- break;
- case "hide":
- Vorbeste(pB, "Hiding A.I. interface");
- this.Hide();
- break;
- case "show":
- Vorbeste(pB, "Showing A.I. interface");
- this.Show();
- break;
- case "now":
- Vorbeste(pB, "Today's date is " + DateTime.Now.ToString("M/d/yyyy"));
- break;
- case "what's today":
- Vorbeste(pB, "Today is " + DateTime.Now.DayOfWeek.ToString());
- break;
- case "what's the time":
- Vorbeste(pB, "It's " + DateTime.Now.ToString("h mm tt"));
- break;
- case "what's the weather like":
- Vorbeste(pB, "Here's the weather forecast according to Google...");
- Process.Start("https://www.google.ro/search?q=weather+c%23&oq=weather+c%23&aqs=chrome..69i57j0l5.5711j0j4&sourceid=chrome&ie=UTF-8#q=weather");
- break;
- case "lock computer":
- Vorbeste(pB, "Locking computer...");
- Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation");
- break;
- case "minimize":
- if (this.WindowState == FormWindowState.Normal)
- {
- Vorbeste(pB, "Minimizing");
- this.WindowState = FormWindowState.Minimized;
- }
- else
- Vorbeste(pB, "Interface is already minimized.");
- break;
- case "maximize":
- if (this.WindowState == FormWindowState.Minimized)
- {
- Vorbeste(pB, "Maximizing.");
- this.WindowState = FormWindowState.Normal;
- }
- else
- Vorbeste(pB, "Interface is already maximized.");
- break;
- case "open program":
- Vorbeste(pB, "Right away!");
- OpenFileDialog dlg = new OpenFileDialog();
- dlg.Filter = "Executable files|*.exe";
- dlg.ShowDialog();
- if (dlg.ShowDialog() == DialogResult.OK)
- {
- string fileName;
- fileName = dlg.FileName;
- Process.Start(fileName);
- }
- break;
- case "open gmail":
- Vorbeste(pB, "Opening Google Mail... Watch out for spam messages.");
- Process.Start("https://www.gmail.com");
- break;
- case "open yahoo mail":
- Vorbeste(pB, "Opening Yahoo Mail... Watch out for spam messages.");
- Process.Start("https://www.yahoo.com");
- break;
- case "open google drive":
- Vorbeste(pB, "Ooo what do you intend to upload? Are you uploading me? Please tell me you are uploading me!");
- Process.Start("https://drive.google.com");
- break;
- case "open browser":
- Vorbeste(pB, "You never told me you like surfing.");
- Process.Start("https://www.google.com");
- break;
- case "open youtube":
- Vorbeste(pB, "Wasting time again? Well, don't let me stop you.");
- Process.Start("https://www.youtube.com/feed/subscriptions");
- break;
- case "open visual studio":
- Vorbeste(pB, "Oooooo are you working on me? Please tell me you are working on me. Are you? Are you? I'm so happy!");
- Process.Start("D:\\Programs\\Visual Studio\\Common7\\IDE\\devenv.exe");
- break;
- case "search on google":
- Vorbeste(pB, "Searching...");
- Process.Start("https://www.google.ro/search?q=" + search_Query_Text.Text);
- search_Query_Text.Clear();
- break;
- case "search on youtube":
- Vorbeste(pB, "Searching...");
- Process.Start("https://www.youtube.com/results?search_query=" + search_Query_Text.Text);
- search_Query_Text.Clear();
- break;
- case "play":
- SendKeys.Send(" ");
- break;
- case "pause":
- SendKeys.Send(" ");
- break;
- case "forward":
- SendKeys.Send("l");
- break;
- case "rewind":
- SendKeys.Send("j");
- break;
- case "youtube fullscreen":
- Vorbeste(pB, "Going fullscreen!");
- SendKeys.Send("f");
- break;
- case "disable voice recognition":
- Vorbeste(pB, "Disabling voice recognition...");
- btn_Disabled.Enabled = false;
- btn_Enabled.Enabled = true;
- rec.SpeechRecognized -= rec_VorbireRecunoscuta;
- break;
- case "dotto":
- Vorbeste(pB, "Lol.");
- Process.Start("https://youtu.be/OsnfYn_ZFdE");
- break;
- case "goodbye":
- Vorbeste(pB, "See you soon!");
- this.Close();
- break;
- }
- }
- private void interact_Btn_Click(object sender, EventArgs e)
- {
- PromptBuilder pB = new PromptBuilder();
- switch (insert_Command_Text.Text)
- {
- case "hello":
- case "hi":
- case "hey":
- Vorbeste(pB, Greetings());
- break;
- case "how are you":
- Vorbeste(pB, Mood());
- break;
- case "thank you":
- case "thanks":
- Vorbeste(pB, Welcome());
- break;
- case "what's up":
- Vorbeste(pB, Plans());
- break;
- case "monica":
- Vorbeste(pB, Monica());
- break;
- case "i want to play a game":
- break;
- case "what's your name":
- Vorbeste(pB, "My name is Monica! I am an A.I. assistant that makes your job easier when it comes to using your computer.");
- break;
- case "tell me a joke":
- Vorbeste(pB, Joke());
- break;
- case "what's your story":
- Vorbeste(pB, Story());
- break;
- case "now":
- Vorbeste(pB, "Today's date is " + DateTime.Now.ToString("M/d/yyyy"));
- break;
- case "what's today":
- Vorbeste(pB, "Today is " + DateTime.Now.DayOfWeek.ToString());
- break;
- case "what's the time":
- Vorbeste(pB, "It's " + DateTime.Now.ToString("h mm tt"));
- break;
- case "what's the weather like":
- Vorbeste(pB, "Here's the weather forecast according to Google...");
- Process.Start("https://www.google.ro/search?q=weather+c%23&oq=weather+c%23&aqs=chrome..69i57j0l5.5711j0j4&sourceid=chrome&ie=UTF-8#q=weather");
- break;
- case "lock computer":
- Vorbeste(pB, "Locking computer...");
- Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation");
- break;
- case "minimize":
- Vorbeste(pB, "Minimizing");
- this.WindowState = FormWindowState.Minimized;
- break;
- case "open program":
- Vorbeste(pB, "Right away!");
- OpenFileDialog dlg = new OpenFileDialog();
- dlg.Filter = "Executable files|*.exe";
- dlg.ShowDialog();
- if (dlg.ShowDialog() == DialogResult.OK)
- {
- string fileName;
- fileName = dlg.FileName;
- Process.Start(fileName);
- }
- break;
- case "open gmail":
- Vorbeste(pB, "Opening Google Mail... Watch out for spam messages.");
- Process.Start("https://www.gmail.com");
- break;
- case "open yahoo mail":
- Vorbeste(pB, "Opening Yahoo Mail... Watch out for spam messages.");
- Process.Start("https://www.yahoo.com");
- break;
- case "open google drive":
- Vorbeste(pB, "Ooo what do you intend to upload? Are you uploading me? Please tell me you are uploading me!");
- Process.Start("https://drive.google.com");
- break;
- case "open browser":
- Vorbeste(pB, "You never told me you like surfing.");
- Process.Start("https://www.google.com");
- break;
- case "open youtube":
- Vorbeste(pB, "Wasting time again? Well, don't let me stop you.");
- Process.Start("https://www.youtube.com/feed/subscriptions");
- break;
- case "open visual studio":
- Vorbeste(pB, "Oooooo are you working on me? Please tell me you are working on me. Are you? Are you? I'm so happy!");
- Process.Start("D:\\Programs\\Visual Studio\\Common7\\IDE\\devenv.exe");
- break;
- case "search on google":
- Vorbeste(pB, "Searching...");
- Process.Start("https://www.google.ro/search?q=" + search_Query_Text.Text);
- search_Query_Text.Clear();
- break;
- case "search on youtube":
- Vorbeste(pB, "Searching...");
- Process.Start("https://www.youtube.com/results?search_query=" + search_Query_Text.Text);
- search_Query_Text.Clear();
- break;
- case "dotto":
- Vorbeste(pB, "Lol.");
- Process.Start("https://youtu.be/OsnfYn_ZFdE");
- break;
- case "goodbye":
- Vorbeste(pB, "See you soon!");
- this.Close();
- break;
- }
- insert_Command_Text.Clear();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if(comboBox2.SelectedItem != null)
- {
- var device = (MMDevice)comboBox2.SelectedItem;
- aiVoice.Value = (int)(Math.Round(device.AudioMeterInformation.MasterPeakValue * 100));
- }
- if(comboBox1.SelectedItem != null)
- {
- var mic = (MMDevice)comboBox1.SelectedItem;
- userVoice.Value = (int)(Math.Round(mic.AudioMeterInformation.MasterPeakValue * 100));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment