/
main.cs
101 lines (87 loc) · 3.32 KB
/
main.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Threading;
using System.Diagnostics;
namespace WindowsFormsApplication13
{
public partial class VPlayer : MetroFramework.Forms.MetroForm
{
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
SpeechSynthesizer sys = new SpeechSynthesizer();
PromptBuilder prmpb = new PromptBuilder();
public VPlayer()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e) //When Speak Button is clicked
{
prmpb.ClearContent();
prmpb.AppendText(textBox1.Text);
sys.Speak(prmpb);
}
private void button1_Click(object sender, EventArgs e) // when "Listen" button is clicked
{
Choices slist = new Choices();
slist.Add(new string[] {"call","call yusha","call ami","parho surah al fatiha","parho","stop","recite surah al fatiha", "surah al fatiha", "search facebook", "search mehran", "search", "jarvis", "google", "open", "open facebook", "open youtube", "open twitter", "open google" });
Grammar gr = new Grammar(new GrammarBuilder(slist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized; //new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
// MessageBox.Show("done");
}
catch
{
return;
}
}
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show("done");
textBox1.Text += e.Result.Text;
if (e.Result.Text == "open google")
{
Process.Start("www.google.com");
sys.Dispose();
}
else if (e.Result.Text == "open facebook")
{
Process.Start("www.facebook.com");
}
else if (e.Result.Text == "open twitter")
{
Process.Start("www.twitter.com");
}
else if (e.Result.Text == "open youtube")
{
Process.Start("www.youtube.com");
}
if ((e.Result.Text == "surah al fatiha") || (e.Result.Text == "recite surah al fatiha") || (e.Result.Text == "parho surah al fatiha"))
{
wmplayer.Visible = true;
wmplayer.URL = @"C:\Users\Yousha Arif\Desktop\001.mp3";
wmplayer.settings.volume = 100;
}
else if ((e.Result.Text == "call yusha")||(e.Result.Text == "call"))
{
prmpb.ClearContent();
prmpb.AppendText("ok");
sys.Speak(prmpb);
Process.Start("Skype"," /callto:youshaarif");
}
}
}
}