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.Synthesis;
- using System.Speech.Recognition;
- using System.Diagnostics;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- SpeechSynthesizer s = new SpeechSynthesizer();
- Choices list = new Choices();
- public Form1()
- {
- SpeechRecognitionEngine rec = new SpeechRecognitionEngine();
- 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" });
- Grammar gr = new Grammar(new GrammarBuilder(list));
- s.SelectVoiceByHints(VoiceGender.Female);
- InitializeComponent();
- try
- {
- rec.RequestRecognizerUpdate();
- rec.LoadGrammar(gr);
- rec.SpeechRecognized += rec_SpeechRecognized;
- rec.SetInputToDefaultAudioDevice();
- rec.RecognizeAsync(RecognizeMode.Multiple);
- }
- catch
- {
- }
- }
- public void say(String h)
- {
- s.Speak(h);
- txtOutput.AppendText(h + "\n");
- }
- private void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
- {
- String r = e.Result.Text;
- if (r.ToLower().StartsWith("bot"))
- {
- r = r.Substring("bot".Length).Trim();
- if (r == "stop")
- {
- Application.Exit();
- }
- if (r == "restart")
- {
- Process.Start(@"C:\Users\AIBot\AIBot.exe");
- Application.Exit();
- }
- //info
- if (r == "hello")
- {
- say("Hi");
- }
- if (r == "how are you")
- {
- say("Great, thanks");
- }
- if (r == "what time is it")
- {
- say(DateTime.Now.ToString("h:mm tt"));
- }
- if (r == "what is today")
- {
- say(DateTime.Now.ToString("dddd, dd MMMM yyyy"));
- }
- //open/close a program.
- if (r == "open chrome" || r == "open google" || r == "open google chrome")
- {
- Process.Start(@"C:\Program Files (x86)\AVAST Software\Browser\Application\AvastBrowser.exe");
- }
- if (r == "close chrome")
- {
- foreach (Process proc in Process.GetProcessesByName("AvastBrowser"))
- {
- proc.Kill();
- }
- }
- if (r == "open youtube")
- {
- Process.Start("https://www.youtube.com/feed/subscriptions");
- }
- if (r == "open rainbow")
- {
- Process.Start("steam://rungameid/359550");
- }
- if (r == "open local disk")
- {
- Process.Start(@"C:\");
- }
- if (r == "open downloads")
- {
- Process.Start(@"D:\Users\Utente\Downloads");
- }
- if (r == "open whatsapp")
- {
- Process.Start(@"C:\Users\Utente\AppData\Local\WhatsApp\WhatsApp.exe");
- }
- }
- }
- private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- Show();
- this.WindowState = FormWindowState.Normal;
- notifyIcon1.Visible = false;
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void pictureBox2_Click(object sender, EventArgs e)
- {
- this.WindowState = FormWindowState.Minimized;
- Hide();
- notifyIcon1.Visible = true;
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
- //how to close programs
- //example: Ehi google, do something, or Alexa, do something... ask how to do that
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement