-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cs
585 lines (471 loc) · 16.9 KB
/
MainWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Discord;
namespace Epsilon_Csharp
{
public partial class EpsilonWindow : Form
{
private String input, confidence;
NameHandler nh = new NameHandler();
GramWordDec gw = new GramWordDec();
MathTimeHandler mt = new MathTimeHandler();
ApplicationManager am = new ApplicationManager();
String output;
int nameSet = 0;
Boolean speechActive = false;
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
SpeechSynthesizer ss = new SpeechSynthesizer();
Boolean awake = false;
int timerDuration = 0;
Boolean isTimerRunning = false;
public EpsilonWindow()
{
String myName = nh.GetName();
InitializeComponent();
if (myName.Equals("none"))
{
label1.Text = "Hi There! Enter your name to get started.";
}
else
{
label1.Text = "Welcome back " + myName + "!";
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void EpsilonWindow_Load(object sender, EventArgs e)
{
Choices commands = new Choices();
commands.Add(gw.myGrammar());
GrammarBuilder gb = new GrammarBuilder();
DictationGrammar dg = new DictationGrammar();
gb.Append(commands, 1, 5);
Grammar gram = new Grammar(gb);
sre.LoadGrammarAsync(gram);
sre.LoadGrammarAsync(dg);
sre.SetInputToDefaultAudioDevice();
sre.SpeechRecognized += sre_SpeechRecognized;
}
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
input = e.Result.Text.ToLower().ToString();
confidence = e.Result.Confidence.ToString();
Console.WriteLine(input);
if ((input.Equals("hey epsilon") || input.Equals("epsilon")) && !(awake))
{
ArrayList ar = new ArrayList();
ar.Add("Yes " + nh.GetName() + "?");
ar.Add("What's up?");
ar.Add("How can I help?");
ar.Add("Whaddya need?");
Random rnd = new Random();
int r = rnd.Next(0, ar.Count-1);
label1.Text = ar[r].ToString();
ss.SpeakAsync(ar[r].ToString());
awake = true;
}
if (!(nh.GetName().Equals("none")) && awake)
{
Console.WriteLine(confidence);
Analyse(input);
}
}
private void button1_Click(object sender, EventArgs e)
{
input = textBox1.Text.ToLower().ToString();
textBox1.Text = "";
if (nh.GetName().Equals("none"))
{
SetName(input);
}
else
{
Analyse(input);
}
}
private void button1_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void EpsilonWindow_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
input = textBox1.Text.ToLower().ToString();
textBox1.Text = "";
}
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
input = textBox1.Text.ToLower().ToString();
textBox1.Text = "";
if (nh.GetName().Equals("none"))
{
SetName(input);
}
else
{
Analyse(input);
}
}
}
private void SetName(String input)
{
nh.ChangeName(input);
label1.Text = "Nice to meet you " + nh.GetName() + "!";
}
private void Analyse(String input)
{
if(input.Equals("hey epsilon") || input.Equals("epsilon"))
{
}
else if (input.Contains("close app"))
{
Application.Exit();
}
else if (input.Contains("what is my name") || input.Contains("what's my name"))
{
//ArrayList output = [ "What's up?", "How can I help?", "Yes " + nh.GetName() ];
label1.Text = "Your name is " + nh.GetName();
ss.SpeakAsync("Your name is " + nh.GetName());
awake = false;
}
else if (input.Contains("who are you"))
{
label1.Text = "My name is Epsilon, I am your virtual assistant";
ss.SpeakAsync("My name is Epsilon, I am your virtual assistant");
awake = false;
}
else if (input.Equals("nevermind"))
{
label1.Text = "";
awake = false;
}
else if (input.Equals("what is the time") || input.Equals("what time is it"))
{
label1.Text = "The time is " + mt.CurrentTime();
ss.SpeakAsync("The time is " + mt.CurrentTime());
awake = false;
}
else if (input.Contains("chrome"))
{
label1.Text = "";
ss.SpeakAsync("Opening Chrome");
am.chrome();
awake = false;
}
else if (input.Equals("open photoshop"))
{
label1.Text = "";
ss.SpeakAsync("Opening photoshop");
am.photoshop();
awake = false;
}
else if (input.Equals("open firefox"))
{
label1.Text = "";
ss.SpeakAsync("Opening firefox");
am.firefox();
awake = false;
}
else if (input.Contains("messenger"))
{
label1.Text = "";
ss.SpeakAsync("Opening Messenger");
am.messenger();
awake = false;
}
else if (input.Contains("amazon"))
{
label1.Text = "";
ss.SpeakAsync("Opening Amazon");
am.amazon();
awake = false;
}
else if (input.Equals("open notepad"))
{
label1.Text = "";
ss.SpeakAsync("Opening Notepad");
am.notepad();
awake = false;
}
else if (input.Equals("open discord"))
{
label1.Text = "";
ss.SpeakAsync("Opening Discord");
am.discord();
awake = false;
}
else if (input.Equals("open youtube"))
{
label1.Text = "";
ss.SpeakAsync("Opening Youtube");
am.youtube();
awake = false;
}
else if (input.Equals("open c cleaner"))
{
label1.Text = "";
ss.SpeakAsync("Opening C-Cleaner");
am.CClean();
awake = false;
}
else if (input.Equals("open powershell"))
{
label1.Text = "";
ss.SpeakAsync("Opening PowerShell");
am.PShell();
awake = false;
}
else if (input.Equals("open dx diag"))
{
label1.Text = "";
ss.SpeakAsync("Opening DX-DIAG");
am.DXDiag();
awake = false;
}
else if (input.Equals("open cmd") || input.Equals("open command prompt"))
{
label1.Text = "";
ss.SpeakAsync("Opening CMD");
am.cmdStart();
awake = false;
}
else if (input.Contains("notepad plus plus"))
{
label1.Text = "";
ss.SpeakAsync("Opening Notepad Plus-Plus");
am.NotepadPlus();
awake = false;
}
else if (input.Contains("internet") || input.Contains("browser"))
{
label1.Text = "";
ss.SpeakAsync("Opening your default browser");
am.DefaultBrowser();
awake = false;
}
else if (input.Equals("open word"))
{
label1.Text = "";
ss.SpeakAsync("Opening Microsoft Word");
am.word();
awake = false;
}
else if (input.Equals("hello there"))
{
label1.Text = "";
ss.SpeakAsync("General Kenoh-beee!");
awake = false;
}
else if (input.Equals("open excel"))
{
label1.Text = "";
ss.SpeakAsync("Opening Microsoft Excel");
am.excel();
awake = false;
}
else if (input.Equals("open powerpoint"))
{
label1.Text = "";
ss.SpeakAsync("Opening Microsoft PowerPoint");
am.PPoint();
awake = false;
}
else if (input.Contains("current song") || input.Contains("this song"))
{
String song = am.CurrentSong();
ss.SpeakAsync(song);
label1.Text = song;
awake = false;
}
else if (input.Contains("next song") || input.Contains("next track"))
{
ss.SpeakAsync("playing next song");
am.nextSong();
awake = false;
}
else if (input.Contains("volume up"))
{
am.VolmUp();
awake = false;
}
else if (input.Contains("volume down"))
{
am.VolmDown();
awake = false;
}
else if (input.Contains("file explorer"))
{
ss.SpeakAsync("Opening File Explorer");
am.explorer();
awake = false;
}
else if (input.Contains("the date"))
{
label1.Text = mt.CurrentDate();
ss.SpeakAsync("It is "+ mt.CurrentDate());
awake = false;
}
else if (input.Contains("last song") || input.Contains("previous song") || input.Contains("last track") || input.Contains("previous track"))
{
ss.SpeakAsync("playing previous song");
am.prevSong();
System.Threading.Thread.Sleep(1000);
am.prevSong();
awake = false;
}
else if (input.Contains("pause song") || input.Contains("play song") || input.Contains("start song") || input.Contains("stop song") || input.Contains("pause music") || input.Contains("play music") || input.Contains("start music") || input.Contains("stop music"))
{
//ss.SpeakAsync("Pausing Spotify");
am.PausePlay();
awake = false;
}
else if (input.Contains("weather"))
{
label1.Text = "Weather provided by Google";
ss.SpeakAsync("Here is the weather for your current location");
am.weather();
awake = false;
}
else if (input.Equals("next app") || input.Equals("alt tab"))
{
label1.Text = "";
ss.SpeakAsync("Alt-Tabbing");
am.nextApp();
awake = false;
}
else if (input.Equals("how much wood could a wood chuck chuck if a wood chuck could chuck wood"))
{
label1.Text = "Really " + nh.GetName() + "?";
ss.SpeakAsync("Really "+ nh.GetName()+"?");
am.nextApp();
awake = false;
}
else if (input.Contains("spotify"))
{
label1.Text = "";
ss.SpeakAsync("Opening spotify");
am.spotify();
awake = false;
}
else if (input.Contains("open skype"))
{
label1.Text = "";
ss.SpeakAsync("Opening skype");
am.skype();
awake = false;
}
else if (input.Contains("steam"))
{
label1.Text = "";
ss.SpeakAsync("Opening steam");
am.steam();
awake = false;
}
else if (input.Contains("timer for"))
{
label1.Text = "";
int timeGrabbed = mt.TimerParser(input);
timerDuration = timeGrabbed * 60;
ss.SpeakAsync("Setting a timer for " + timeGrabbed.ToString() + " minutes");
isTimerRunning = true;
timer1.Start();
timer1.Interval = 1000; // in miliseconds
awake = false;
}
else if (input.Contains("stop timer"))
{
if (isTimerRunning)
{
label1.Text = "Timer Stopped";
ss.SpeakAsync("Timer Stopped");
stopTimer();
}
else
{
label1.Text = "No Timer Running";
ss.SpeakAsync("No Timer Running");
}
awake = false;
}
else if (input.Equals("shutdown pc"))
{
label1.Text = "";
ss.SpeakAsync("Goodbye");
am.shutdown();
awake = false;
}
else if (input.Contains("plus") || input.Contains("add") || input.Contains("minus") || input.Contains("subtract") || input.Contains("multiply") || input.Contains("times") || input.Contains("divide"))
{
label1.Text = mt.Calc(input);
ss.SpeakAsync(mt.Calc(input));
awake = false;
}
else if (input.Contains("google") || input.Contains("what is") || input.Contains("search") || input.Contains("how do i"))
{
label1.Text = "";
ss.SpeakAsync("searching google for " + am.googSearch(input));
awake = false;
}
else if (input.Equals("debug all apps"))
{
am.GetProcessesDebug();
}
else
{
label1.Text = "Sorry, I'm afraid I can't help with that";
ss.SpeakAsync("Sorry, I'm afraid I can't help with that");
awake = false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if(timerDuration > 0)
{
timerDuration--;
label2.Text = timerDuration / 60 + ":" + ((timerDuration % 60) >= 10 ? (timerDuration % 60).ToString(): "0" + timerDuration%60);
}
else
{
isTimerRunning = false;
timer1.Stop();
label2.Text = "";
ss.SpeakAsync("Your Timer Has Finished");
}
}
private void stopTimer()
{
timer1.Stop();
label2.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
if (!(speechActive))
{
button2.Text = "Disable Speech Recognition";
speechActive = true;
sre.RecognizeAsync(RecognizeMode.Multiple);
}
else
{
button2.Text = "Enable Speech Recognition";
sre.RecognizeAsyncStop();
speechActive = false;
}
}
}
}