Advertisement
Guest User

Untitled

a guest
May 11th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.75 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.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.Speech.Synthesis;
  12. using System.Speech.Recognition;
  13. using System.Diagnostics;
  14. using System.Windows.Forms;
  15. using WMPLib;
  16. using System.Threading;
  17.  
  18. namespace Friday
  19. {
  20. public partial class Form1 : Form
  21. {
  22. //grammar and response file
  23. string[] grammarFile = File.ReadAllLines(@"C:\Users\Sherick Yu\Desktop\user.txt.txt");
  24. string[] responseFile = File.ReadAllLines(@"C:\Users\Sherick Yu\Desktop\friday.txt.txt");
  25.  
  26. //speech synthesis
  27. SpeechSynthesizer speechSynth = new SpeechSynthesizer();
  28.  
  29. //speech recognition
  30. Choices grammarList = new Choices();
  31. SpeechRecognitionEngine speechRecognition = new SpeechRecognitionEngine();
  32.  
  33. Boolean wake = false;
  34.  
  35.  
  36.  
  37.  
  38. public Form1()
  39. {
  40. //initialize grammar
  41. grammarList.Add(grammarFile);
  42. Grammar grammar = new Grammar(new GrammarBuilder(grammarList));
  43.  
  44. try
  45. {
  46. speechRecognition.RequestRecognizerUpdate();
  47. speechRecognition.LoadGrammar(grammar);
  48. speechRecognition.SpeechRecognized += rec_SpeechRecognized;
  49. speechRecognition.SetInputToDefaultAudioDevice();
  50. speechRecognition.RecognizeAsync(RecognizeMode.Multiple);
  51. }
  52. catch { return; }
  53.  
  54. //custom speech settings
  55. speechSynth.SelectVoiceByHints(VoiceGender.Female);
  56. speechSynth.Speak("hello, i am friday. a program made by edward hanes");
  57. InitializeComponent();
  58.  
  59. }
  60.  
  61. //killing programs command
  62. public static void KillProg(string speechSynth)
  63. {
  64. Process[] procs = null;
  65.  
  66. try
  67. {
  68. procs = Process.GetProcessesByName(speechSynth);
  69. Process prog = procs[0];
  70.  
  71. if (!prog.HasExited)
  72. {
  73. prog.Kill();
  74. }
  75. }
  76. finally
  77. {
  78. if (procs != null)
  79. {
  80. foreach (Process p in procs)
  81. {
  82. p.Dispose();
  83. }
  84. }
  85. }
  86. }
  87.  
  88.  
  89. public void say(string text)
  90. {
  91. speechSynth.SpeakAsync(text);
  92. textBox1.AppendText(text + "\n");
  93. }
  94.  
  95.  
  96.  
  97. private void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs d)
  98. {
  99. string result = d.Result.Text;
  100. int resp = Array.IndexOf(grammarFile, result);
  101.  
  102.  
  103.  
  104. if (result.Contains("wake"))
  105. {
  106. wake = true;
  107. textBox5.Text = "Status: Online";
  108. }
  109.  
  110. if (result.Contains("sleep"))
  111. {
  112.  
  113. wake = false;
  114. textBox5.Text = "Status: Offline";
  115. }
  116.  
  117. if (wake == true)
  118. {
  119.  
  120. if (responseFile[resp].IndexOf('+') == 0)
  121. {
  122. List<string> responses = responseFile[resp].Replace('+', ' ').Split('/').Reverse().ToList();
  123. Random r = new Random();
  124. say(responses[r.Next(responses.Count)]);
  125. }
  126. else
  127. {
  128.  
  129.  
  130. //extra commands *
  131. if (responseFile[resp].IndexOf('*') == 0)
  132. {
  133. if (result.Contains("time"))
  134. {
  135. say(DateTime.Now.ToString(@"hh\:mm tt"));
  136. }
  137.  
  138. if (result.Contains("date"))
  139. {
  140. say(DateTime.Now.ToString(@"MMMM/dd/yyyy"));
  141. }
  142.  
  143.  
  144. if (result.Contains("chrome"))
  145. {
  146. say("opening google chrome");
  147. Process.Start(@"chrome.exe", "--incognito https://www.google.com/");
  148.  
  149. }
  150.  
  151.  
  152. if (result.Contains("facebook"))
  153. {
  154. say("opening facebook");
  155. Process.Start(@"chrome.exe", "--incognito https://www.facebook.com/");
  156.  
  157. }
  158.  
  159. if (result.Contains("youtube"))
  160. {
  161. say("opening youtube");
  162. Process.Start(@"chrome.exe", "--incognito https://www.youtube.com/");
  163.  
  164. }
  165.  
  166. if (result.Contains("nba"))
  167. {
  168. say("here are the latest news about nba");
  169. Process.Start(@"chrome.exe", "--incognito https://www.nba.com/scores#/");
  170.  
  171. }
  172.  
  173. if (result.Contains("crypto"))
  174. {
  175. say("here are the latest news about cryptocurrency");
  176. Process.Start(@"chrome.exe", "--incognito https://coinmarketcap.com/all/views/all/");
  177.  
  178. }
  179.  
  180. if (result.Contains("word"))
  181. {
  182. say("opening word");
  183. Process.Start(@"C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE");
  184. }
  185.  
  186. if (result.Contains("ppt"))
  187. {
  188. say("opening powerpoint");
  189. Process.Start(@"C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE");
  190. }
  191.  
  192. if (result.Contains("steam"))
  193. {
  194. say("opening steam");
  195. Process.Start(@"C:\Program Files (x86)\Steam\Steam.exe");
  196. }
  197.  
  198. if (result.Contains("epic games"))
  199. {
  200. say("opening epic games");
  201. Process.Start(@"C:\Program Files (x86)\Epic Games\Launcher\Portal\Binaries\Win32\EpicGamesLauncher.exe");
  202. }
  203.  
  204.  
  205.  
  206. if (result.Contains("weather"))
  207. {
  208. say("here is the weather today");
  209. Process.Start(@"chrome.exe", "--incognito https://www.accuweather.com/en/ph/manila/264885/weather-forecast/264885");
  210. }
  211.  
  212. //nircmd commands
  213. if (result.Contains("monitor off"))
  214. {
  215. say("turning off monitor");
  216. Process monitor_off = new Process();
  217. monitor_off.StartInfo.FileName = "C:\\nircmd.exe";
  218. monitor_off.StartInfo.Arguments = "monitor off";
  219. monitor_off.Start();
  220.  
  221. }
  222.  
  223. if (result.Contains("increase volume"))
  224. {
  225. say("increasing volume");
  226. Process increase_volume = new Process();
  227. increase_volume.StartInfo.FileName = "C:\\nircmd.exe";
  228. increase_volume.StartInfo.Arguments = "changesysvolume 6000";
  229. increase_volume.Start();
  230. }
  231.  
  232. if (result.Contains("decrease volume"))
  233. {
  234. say("decreasing volume");
  235. Process dec_vol = new Process();
  236. dec_vol.StartInfo.FileName = "C:\\nircmd.exe";
  237. dec_vol.StartInfo.Arguments = "changesysvolume -5000";
  238. dec_vol.Start();
  239.  
  240. }
  241.  
  242. if (result.Contains("max volume"))
  243. {
  244. say("volume 100%");
  245. Process max_volume = new Process();
  246. max_volume.StartInfo.FileName = "C:\\nircmd.exe";
  247. max_volume.StartInfo.Arguments = "setsysvolume 65535";
  248. max_volume.Start();
  249.  
  250. }
  251.  
  252.  
  253. if (result.Contains("mute"))
  254. {
  255.  
  256. Process mute = new Process();
  257. mute.StartInfo.FileName = "C:\\nircmd.exe";
  258. mute.StartInfo.Arguments = "mutesysvolume 1";
  259. mute.Start();
  260.  
  261. }
  262.  
  263. if (result.Contains("unmute"))
  264. {
  265. say("unmuted");
  266. Process unmute = new Process();
  267. unmute.StartInfo.FileName = "C:\\nircmd.exe";
  268. unmute.StartInfo.Arguments = "mutesysvolume 0";
  269. unmute.Start();
  270.  
  271. }
  272.  
  273. if (result.Contains("recycle bin"))
  274. {
  275. say("recycle bin has been emptied");
  276. Process recycle_bin = new Process();
  277. recycle_bin.StartInfo.FileName = "C:\\nircmd.exe";
  278. recycle_bin.StartInfo.Arguments = "emptybin";
  279. recycle_bin.Start();
  280.  
  281. }
  282.  
  283. if (result.Contains("turn off computer"))
  284. {
  285. say("turning off computer");
  286. Process off_computer = new Process();
  287. off_computer.StartInfo.FileName = "C:\\nircmd.exe";
  288. off_computer.StartInfo.Arguments = "exitwin poweroff";
  289. off_computer.Start();
  290.  
  291. }
  292.  
  293. if (result.Contains("goodbye"))
  294. {
  295. say("goodbye sir. i love you 3000");
  296. Process.Start(@"chrome.exe", "--incognito https://www.youtube.com/watch?v=QMe8e5GcY0c");
  297. System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
  298. timer.Interval = 4000;
  299. timer.Tick += new EventHandler(timer1_Tick);
  300. timer.Start();
  301. wake = false;
  302.  
  303. }
  304.  
  305. }
  306.  
  307. else
  308. {
  309. say(responseFile[resp]);
  310.  
  311. }
  312.  
  313.  
  314.  
  315.  
  316. }
  317. }
  318. textBox2.AppendText(d.Result.Text + "\n");
  319.  
  320. }
  321.  
  322. private void timer_Tick(object sender, EventArgs e)
  323. {
  324.  
  325. }
  326.  
  327. public static void ExecuteCommand(string Command) //nircmd
  328. {
  329. System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/result " + Command);
  330. processStartInfo.RedirectStandardOutput = true;
  331. processStartInfo.UseShellExecute = false;
  332.  
  333. processStartInfo.CreateNoWindow = true;
  334.  
  335. System.Diagnostics.Process proc = new System.Diagnostics.Process();
  336. proc.StartInfo = processStartInfo;
  337. proc.Start();
  338. proc.Close();
  339. }
  340.  
  341.  
  342.  
  343. private void Form1_Load(object sender, EventArgs e)
  344. {
  345.  
  346. }
  347.  
  348. private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
  349. {
  350.  
  351. }
  352.  
  353. private void textBox1_TextChanged(object sender, EventArgs e)
  354. {
  355.  
  356. }
  357.  
  358. private void timer1_Tick(object sender, EventArgs e)
  359. {
  360. this.Close();
  361. }
  362.  
  363. private void textBox5_TextChanged(object sender, EventArgs e)
  364. {
  365.  
  366. }
  367.  
  368. private void textBox2_TextChanged(object sender, EventArgs e)
  369. {
  370.  
  371. }
  372.  
  373. private void textBox3_TextChanged(object sender, EventArgs e)
  374. {
  375.  
  376. }
  377.  
  378. private void textBox4_TextChanged(object sender, EventArgs e)
  379. {
  380.  
  381. }
  382. }
  383. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement