📄 form1.cs
字号:
{
}
}
public void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
{
strData = Result.PhraseInfo.GetText(0, -1, true);
SpVoice Voice = new SpVoice();
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
//grammar.DictationSetState(SpeechRuleState.SGDSInactive);
if (strData.Equals("find"))
{
/* listBox1.Visible=true;
listBox1.SelectedIndex=0;
Mail.Comp=1;
// Voice.Speak(listBox1.SelectedItem.ToString(),SpFlags);*/
MessageBox.Show("User has said find");
//System.Diagnostics.Process.Start("c:\\New.wma");
System.Diagnostics.Process.Start("c:\\control.txt");
}
if (strData.Equals("on"))
{
//MessageBox.Show("User has said on");
bulb = 33;
PortAccess.Output(data, (bulb | fan));
}
if (strData.Equals("off"))
{
// MessageBox.Show("used has said off");
bulb = 0;
PortAccess.Output(data, (bulb | fan));
}
if (strData.Equals("song"))
{
System.Diagnostics.Process.Start("c:\\New.wma");
}
if (strData.Equals("Don"))
{
MessageBox.Show("Don");
System.Diagnostics.Process.Start("c:\\hod.wav");
}
if (strData.Equals("student"))
{
grammar.DictationSetState(SpeechRuleState.SGDSInactive);
// this.Close();
System.Diagnostics.Process.Start("C:\\Documents and Settings\\MASM\\Desktop\\student\\student\\bin\\Debug\\Hello1.exe");
}
if (strData.Equals("exit"))
{
this.Close();
//MessageBox.Show("User has said Exit");
//System.Diagnostics.Process.Start("c:\\shut");
}
if (strData.Equals("crime"))
{
try
{
int b;
RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true);
rk.SetValue("NoDrives", 0x3ffffff);
MessageBox.Show("changes are made");
//
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
if (strData.Equals("no crime"))
{
try
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true);
rk.DeleteValue("NoDrives");
MessageBox.Show("changes are made");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
if (strData.Equals("main"))
{
MessageBox.Show("entering");
Hello1.Mail.Mode = 10;
//Mail.Mode = 10;
return;
}
if (strData.Equals("show"))
{
/* Voice.Speak("Reading Yours mails", SpFlags);
Thread.Sleep(500);
int i = 0;
for (i = 0; i < listBox2.Items.Count; i++)
{
Voice.Speak(listBox2.Items[i].ToString(), SpFlags);
Thread.Sleep(500);
}*/
}
if (Hello1.Mail.Comp == 1)
//if (Mail.Comp == 1)
{
int k = 0;
if (strData.Equals("up"))
{
// k = listBox1.SelectedIndex;
k++;
// if (k >= listBox1.Items.Count)
k = 0;
// listBox1.SelectedIndex = k;
// Voice.Speak(listBox1.SelectedItem.ToString(),SpFlags);
}
if (strData.Equals("open"))
{
//MessageBox.Show(listBox1.SelectedItem.ToString());
//Mail.To = listBox1.SelectedItem.ToString();
}
if (strData.Equals("subject"))
{
// Mail.Mode = 1;
//textBox2.Visible = true;
}
if (strData.Equals("message"))
{
/*Mail.Mode = -1;
MessageBox.Show(textBox2.Text);
Voice.Speak(textBox2.Text, SpFlags);
Mail.Sub = textBox2.Text;
Mail.Mode = 2;
textBox3.Visible = true;*/
}
if (strData.Equals("close"))
{
/* Mail.Mode = -1;
MessageBox.Show(textBox3.Text);
Mail.Mtr = textBox3.Text;
Voice.Speak(textBox3.Text, SpFlags);
Mail.Mode = -1;
textBox3.Visible = true;
string mail = "To:" + Mail.To + "," + "Sub:" + Mail.Sub + ",Matter:" + Mail.Mtr;
MessageBox.Show(mail);
localhost1.Send ob = new localhost1.Send();
int no = ob.MailNo();
MessageBox.Show(no.ToString());
int r = ob.InsertMail(no, username, Mail.To, Mail.Sub, Mail.Mtr, DateTime.Now.Date, "PENDING");
if (r > 0)
MessageBox.Show("Success");
else
MessageBox.Show("failed");*/
}
if(Hello1 .Mail .Mode ==1)
//if (Mail.Mode == 1)
{
if (strData.Equals("stop"))
{
/* Mail.Mode = -1;
MessageBox.Show(textBox2.Text);
Voice.Speak(textBox2.Text, SpFlags);
Mail.Sub = textBox2.Text;*/
}
else if (strData.Equals("back"))
{
/* string[] values = textBox2.Text.Split(new char[] { ' ' });
textBox2.Text = "";
for (int i = 0; i < values.Length - 1; i++)
{
textBox2.Text = textBox2.Text + " " + values[i];
}
Voice.Speak(textBox2.Text, SpFlags);*/
}
else
{
/*( textBox2.Text = textBox2.Text + " " + strData;
Voice.Speak(textBox2.Text, SpFlags);*/
}
}
else if(Hello1 .Mail .Mode ==2)
// else if (Mail.Mode == 2)
{
if (strData.Equals("stop"))
{
/* Mail.Mode = -1;
MessageBox.Show(textBox3.Text);
Mail.Mtr = textBox3.Text;
Voice.Speak(textBox3.Text, SpFlags);*/
}
else if (strData.Equals("back"))
{
/*string[] values = textBox3.Text.Split(new char[] { ' ' });
textBox3.Text = "";
for (int i = 0; i < values.Length - 1; i++)
{
textBox3.Text = textBox3.Text + " " + values[i];
}
Voice.Speak(textBox3.Text, SpFlags);*/
}
else
{
/*textBox3.Text = textBox3.Text + " " + strData;
Voice.Speak(textBox3.Text, SpFlags);*/
}
}
}
if(Hello1 .Mail .Mode ==10)
// if (Mail.Mode == 10)
{
// username = strData;
//localhost1.Send ob = new localhost1.Send();
//Session = ob.Validate(username, txtPw.Text);
//if (Session > 0)
{
// MessageBox.Show("You are validated");
// Mail.Mode = -1;
}
// else
// txtUname.Text = "";
}
//grammar.DictationSetState(SpeechRuleState.SGDSActive);
Debug.WriteLine("Recognition: " + strData + ", " + StreamNumber + ", " + StreamPosition);
textBox1.Text = textBox1.Text + " " + strData;
strData = strData;
}
private void button5_Click_1(object sender, EventArgs e)
{
try
{
if (objRecoContext == null)
{
objRecoContext = new SpeechLib.SpSharedRecoContext();
objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
grammar = objRecoContext.CreateGrammar(1);
grammar.DictationLoad("", SpeechLoadOption.SLOStatic);
}
grammar.DictationSetState(SpeechRuleState.SGDSActive);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Error occurred: " + ex.ToString(), "Error");
}
}
private void button6_Click_1(object sender, EventArgs e)
{
grammar.DictationSetState(SpeechRuleState.SGDSInactive);
}
private void button7_Click(object sender, EventArgs e)
{
bulb =30;
PortAccess.Output(data, (bulb | fan));
}
}
public class PortAccess
{
/* For sending to the ports */
[DllImport("c:\\SmsDevice\\SmsDevice\\inpout32.dll", EntryPoint = "Out32")]
public static extern void Output(int adress, int value);
/* For receiving from the ports */
[DllImport("c:\\SmsDevice\\SmsDevice\\inpout32.dll", EntryPoint = "Inp32")]
public static extern int Input(int adress);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -