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.IO;
- 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;
- using System.Windows.Forms;
- using WMPLib;
- using System.Threading;
- namespace Friday
- {
- public partial class Form1 : Form
- {
- //grammar and response file
- string[] grammarFile = File.ReadAllLines(@"C:\Users\Sherick Yu\Desktop\user.txt.txt");
- string[] responseFile = File.ReadAllLines(@"C:\Users\Sherick Yu\Desktop\friday.txt.txt");
- //speech synthesis
- SpeechSynthesizer speechSynth = new SpeechSynthesizer();
- //speech recognition
- Choices grammarList = new Choices();
- SpeechRecognitionEngine speechRecognition = new SpeechRecognitionEngine();
- Boolean wake = false;
- public Form1()
- {
- //initialize grammar
- grammarList.Add(grammarFile);
- Grammar grammar = new Grammar(new GrammarBuilder(grammarList));
- try
- {
- speechRecognition.RequestRecognizerUpdate();
- speechRecognition.LoadGrammar(grammar);
- speechRecognition.SpeechRecognized += rec_SpeechRecognized;
- speechRecognition.SetInputToDefaultAudioDevice();
- speechRecognition.RecognizeAsync(RecognizeMode.Multiple);
- }
- catch { return; }
- //custom speech settings
- speechSynth.SelectVoiceByHints(VoiceGender.Female);
- speechSynth.Speak("hello, i am friday. a program made by edward hanes");
- InitializeComponent();
- }
- //killing programs command
- public static void KillProg(string speechSynth)
- {
- Process[] procs = null;
- try
- {
- procs = Process.GetProcessesByName(speechSynth);
- Process prog = procs[0];
- if (!prog.HasExited)
- {
- prog.Kill();
- }
- }
- finally
- {
- if (procs != null)
- {
- foreach (Process p in procs)
- {
- p.Dispose();
- }
- }
- }
- }
- public void say(string text)
- {
- speechSynth.SpeakAsync(text);
- textBox1.AppendText(text + "\n");
- }
- private void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs d)
- {
- string result = d.Result.Text;
- int resp = Array.IndexOf(grammarFile, result);
- if (result.Contains("wake"))
- {
- wake = true;
- textBox5.Text = "Status: Online";
- }
- if (result.Contains("sleep"))
- {
- wake = false;
- textBox5.Text = "Status: Offline";
- }
- if (wake == true)
- {
- if (responseFile[resp].IndexOf('+') == 0)
- {
- List<string> responses = responseFile[resp].Replace('+', ' ').Split('/').Reverse().ToList();
- Random r = new Random();
- say(responses[r.Next(responses.Count)]);
- }
- else
- {
- //extra commands *
- if (responseFile[resp].IndexOf('*') == 0)
- {
- if (result.Contains("time"))
- {
- say(DateTime.Now.ToString(@"hh\:mm tt"));
- }
- if (result.Contains("date"))
- {
- say(DateTime.Now.ToString(@"MMMM/dd/yyyy"));
- }
- if (result.Contains("chrome"))
- {
- say("opening google chrome");
- Process.Start(@"chrome.exe", "--incognito https://www.google.com/");
- }
- if (result.Contains("facebook"))
- {
- say("opening facebook");
- Process.Start(@"chrome.exe", "--incognito https://www.facebook.com/");
- }
- if (result.Contains("youtube"))
- {
- say("opening youtube");
- Process.Start(@"chrome.exe", "--incognito https://www.youtube.com/");
- }
- if (result.Contains("nba"))
- {
- say("here are the latest news about nba");
- Process.Start(@"chrome.exe", "--incognito https://www.nba.com/scores#/");
- }
- if (result.Contains("crypto"))
- {
- say("here are the latest news about cryptocurrency");
- Process.Start(@"chrome.exe", "--incognito https://coinmarketcap.com/all/views/all/");
- }
- if (result.Contains("word"))
- {
- say("opening word");
- Process.Start(@"C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE");
- }
- if (result.Contains("ppt"))
- {
- say("opening powerpoint");
- Process.Start(@"C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE");
- }
- if (result.Contains("steam"))
- {
- say("opening steam");
- Process.Start(@"C:\Program Files (x86)\Steam\Steam.exe");
- }
- if (result.Contains("epic games"))
- {
- say("opening epic games");
- Process.Start(@"C:\Program Files (x86)\Epic Games\Launcher\Portal\Binaries\Win32\EpicGamesLauncher.exe");
- }
- if (result.Contains("weather"))
- {
- say("here is the weather today");
- Process.Start(@"chrome.exe", "--incognito https://www.accuweather.com/en/ph/manila/264885/weather-forecast/264885");
- }
- //nircmd commands
- if (result.Contains("monitor off"))
- {
- say("turning off monitor");
- Process monitor_off = new Process();
- monitor_off.StartInfo.FileName = "C:\\nircmd.exe";
- monitor_off.StartInfo.Arguments = "monitor off";
- monitor_off.Start();
- }
- if (result.Contains("increase volume"))
- {
- say("increasing volume");
- Process increase_volume = new Process();
- increase_volume.StartInfo.FileName = "C:\\nircmd.exe";
- increase_volume.StartInfo.Arguments = "changesysvolume 6000";
- increase_volume.Start();
- }
- if (result.Contains("decrease volume"))
- {
- say("decreasing volume");
- Process dec_vol = new Process();
- dec_vol.StartInfo.FileName = "C:\\nircmd.exe";
- dec_vol.StartInfo.Arguments = "changesysvolume -5000";
- dec_vol.Start();
- }
- if (result.Contains("max volume"))
- {
- say("volume 100%");
- Process max_volume = new Process();
- max_volume.StartInfo.FileName = "C:\\nircmd.exe";
- max_volume.StartInfo.Arguments = "setsysvolume 65535";
- max_volume.Start();
- }
- if (result.Contains("mute"))
- {
- Process mute = new Process();
- mute.StartInfo.FileName = "C:\\nircmd.exe";
- mute.StartInfo.Arguments = "mutesysvolume 1";
- mute.Start();
- }
- if (result.Contains("unmute"))
- {
- say("unmuted");
- Process unmute = new Process();
- unmute.StartInfo.FileName = "C:\\nircmd.exe";
- unmute.StartInfo.Arguments = "mutesysvolume 0";
- unmute.Start();
- }
- if (result.Contains("recycle bin"))
- {
- say("recycle bin has been emptied");
- Process recycle_bin = new Process();
- recycle_bin.StartInfo.FileName = "C:\\nircmd.exe";
- recycle_bin.StartInfo.Arguments = "emptybin";
- recycle_bin.Start();
- }
- if (result.Contains("turn off computer"))
- {
- say("turning off computer");
- Process off_computer = new Process();
- off_computer.StartInfo.FileName = "C:\\nircmd.exe";
- off_computer.StartInfo.Arguments = "exitwin poweroff";
- off_computer.Start();
- }
- if (result.Contains("goodbye"))
- {
- say("goodbye sir. i love you 3000");
- Process.Start(@"chrome.exe", "--incognito https://www.youtube.com/watch?v=QMe8e5GcY0c");
- System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
- timer.Interval = 4000;
- timer.Tick += new EventHandler(timer1_Tick);
- timer.Start();
- wake = false;
- }
- }
- else
- {
- say(responseFile[resp]);
- }
- }
- }
- textBox2.AppendText(d.Result.Text + "\n");
- }
- private void timer_Tick(object sender, EventArgs e)
- {
- }
- public static void ExecuteCommand(string Command) //nircmd
- {
- System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/result " + Command);
- processStartInfo.RedirectStandardOutput = true;
- processStartInfo.UseShellExecute = false;
- processStartInfo.CreateNoWindow = true;
- System.Diagnostics.Process proc = new System.Diagnostics.Process();
- proc.StartInfo = processStartInfo;
- proc.Start();
- proc.Close();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- this.Close();
- }
- private void textBox5_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox3_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox4_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement