Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Speech.Synthesis;
  11. using System.Speech.Recognition;
  12. using System.Diagnostics;
  13.  
  14. namespace WindowsFormsApp1
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.  
  19.         SpeechSynthesizer s = new SpeechSynthesizer();
  20.         Choices list = new Choices();
  21.  
  22.  
  23.         public Form1()
  24.         {
  25.  
  26.             SpeechRecognitionEngine rec = new SpeechRecognitionEngine();
  27.  
  28.             list.Add(new String[] { "hello", "how are you", "what time is it", "what is today", "open chrome", "open google", "open youtube", "open rainbow", "restart", "stop", "close chrome", "open local disk", "open downloads", "open whatsapp" });
  29.  
  30.             Grammar gr = new Grammar(new GrammarBuilder(list));
  31.  
  32.  
  33.            
  34.  
  35.  
  36.             s.SelectVoiceByHints(VoiceGender.Female);
  37.  
  38.  
  39.  
  40.             InitializeComponent();
  41.  
  42.             try
  43.             {
  44.                 rec.RequestRecognizerUpdate();
  45.                 rec.LoadGrammar(gr);
  46.                 rec.SpeechRecognized += rec_SpeechRecognized;
  47.                 rec.SetInputToDefaultAudioDevice();
  48.                 rec.RecognizeAsync(RecognizeMode.Multiple);
  49.             }
  50.             catch
  51.             {
  52.             }
  53.         }
  54.  
  55.         public void say(String h)
  56.         {
  57.             s.Speak(h);
  58.             txtOutput.AppendText(h + "\n");
  59.  
  60.         }
  61.  
  62.  
  63.         private void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
  64.         {
  65.             String r = e.Result.Text;
  66.  
  67.             if (r.ToLower().StartsWith("bot"))
  68.             {
  69.                 r = r.Substring("bot".Length).Trim();
  70.  
  71.                 if (r == "stop")
  72.                 {
  73.                     Application.Exit();
  74.                 }
  75.  
  76.                 if (r == "restart")
  77.                 {
  78.                     Process.Start(@"C:\Users\AIBot\AIBot.exe");
  79.                     Application.Exit();
  80.                 }
  81.  
  82.                 //info
  83.  
  84.                 if (r == "hello")
  85.                 {
  86.                     say("Hi");
  87.                 }
  88.  
  89.                 if (r == "how are you")
  90.                 {
  91.                     say("Great, thanks");
  92.                 }
  93.  
  94.                 if (r == "what time is it")
  95.                 {
  96.                     say(DateTime.Now.ToString("h:mm tt"));
  97.                 }
  98.  
  99.                 if (r == "what is today")
  100.                 {
  101.                     say(DateTime.Now.ToString("dddd, dd MMMM yyyy"));
  102.                 }
  103.  
  104.                 //open/close a program.
  105.  
  106.                 if (r == "open chrome" || r == "open google" || r == "open google chrome")
  107.                 {
  108.                     Process.Start(@"C:\Program Files (x86)\AVAST Software\Browser\Application\AvastBrowser.exe");
  109.                 }
  110.  
  111.                 if (r == "close chrome")
  112.                 {
  113.                     foreach (Process proc in Process.GetProcessesByName("AvastBrowser"))
  114.                     {
  115.                         proc.Kill();
  116.                     }
  117.                 }
  118.  
  119.                 if (r == "open youtube")
  120.                 {
  121.                     Process.Start("https://www.youtube.com/feed/subscriptions");
  122.                 }
  123.  
  124.                 if (r == "open rainbow")
  125.                 {
  126.                     Process.Start("steam://rungameid/359550");
  127.                 }
  128.  
  129.                 if (r == "open local disk")
  130.                 {
  131.                     Process.Start(@"C:\");
  132.                 }
  133.  
  134.                 if (r == "open downloads")
  135.                 {
  136.                     Process.Start(@"D:\Users\Utente\Downloads");
  137.                 }
  138.  
  139.                 if (r == "open whatsapp")
  140.                 {
  141.                     Process.Start(@"C:\Users\Utente\AppData\Local\WhatsApp\WhatsApp.exe");
  142.                 }
  143.  
  144.             }
  145.         }
  146.  
  147.  
  148.  
  149.  
  150.         private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
  151.         {
  152.             Show();
  153.             this.WindowState = FormWindowState.Normal;
  154.             notifyIcon1.Visible = false;
  155.         }
  156.  
  157.         private void pictureBox1_Click(object sender, EventArgs e)
  158.         {
  159.             Application.Exit();
  160.         }
  161.  
  162.         private void pictureBox2_Click(object sender, EventArgs e)
  163.         {
  164.             this.WindowState = FormWindowState.Minimized;
  165.             Hide();
  166.             notifyIcon1.Visible = true;
  167.         }
  168.  
  169.         private void textBox1_TextChanged(object sender, EventArgs e)
  170.         {
  171.  
  172.         }
  173.     }
  174. }
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. //how to close programs
  182. //example: Ehi google, do something, or Alexa, do something...   ask how to do that
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement