C# 贾维斯反应时间太长了
我正在用c#制作jarvis。我把它编好了,一旦我们说了什么,贾维斯就会花很长时间回复。回复需要10-15分钟,有时甚至不回复。我希望贾维斯在我发出讲话命令后尽快做出反应C# 贾维斯反应时间太长了,c#,speech-recognition,C#,Speech Recognition,我正在用c#制作jarvis。我把它编好了,一旦我们说了什么,贾维斯就会花很长时间回复。回复需要10-15分钟,有时甚至不回复。我希望贾维斯在我发出讲话命令后尽快做出反应 using System; using System.IO; using System.Speech.Recognition; using System.Speech.Synthesis; using System.Windows.Forms; namespace Jarvis
using System;
using System.IO;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Windows.Forms;
namespace Jarvis
{
public partial class Form1 : Form
{
SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
SpeechSynthesizer JARVIS = new SpeechSynthesizer();
string QEvent;
string ProcWindow;
double timer = 10;
int count = 1;
Random rnd = new Random();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
_recognizer.SetInputToDefaultAudioDevice();
_recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Users\Ashwini\Desktop\Jarvis\Jarvis\bin\Debug\commands.txt")))));
_recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
_recognizer.RecognizeAsync(RecognizeMode.Multiple);
}
void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
int ranNum = rnd.Next(1, 10);
string speech = e.Result.Text;
switch (speech)
{
case "hello":
case "hello jarvis":
if (ranNum < 6) { JARVIS.Speak("Hello sir"); }
else if (ranNum > 5) { JARVIS.Speak("Hello"); }
break;
case "goodbye":
case "goodbye jarvis":
case "close":
case "close jarvis":
JARVIS.Speak("Until next time");
Close();
break;
case "jarvis":
if (ranNum < 5) { QEvent = ""; JARVIS.Speak("Yes sir"); }
else if (ranNum > 4) { QEvent = ""; JARVIS.Speak("Yes?"); }
break;
//WEBSITES
case "open google":
System.Diagnostics.Process.Start("https://www.google.com/");
break;
case "open my facebook":
System.Diagnostics.Process.Start("https://www.facebook.com/");
break;
case "open gmail":
System.Diagnostics.Process.Start("https://www.google.com/gmail/");
break;
//SHELL COMMANDS
case "open this pc":
System.Diagnostics.Process.Start("This PC");
JARVIS.Speak("Loading");
break;
case "open my folder":
System.Diagnostics.Process.Start("F:");
JARVIS.Speak("Loading");
break;
//CLOSE PROGRAMS
case "close this pc":
ProcWindow = "This PC";
StopWindow();
break;
//CONDITION OF DAY
case "what time is it":
DateTime now = DateTime.Now;
string time = now.GetDateTimeFormats('t')[0];
JARVIS.Speak(time);
break;
case "what day is it":
JARVIS.Speak(DateTime.Today.ToString("dddd"));
break;
case "whats the date":
case "whats todays date":
JARVIS.Speak(DateTime.Today.ToString("dd-MM-yyyy"));
break;
//OTHER COMMANDS
case "go fullscreen":
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
TopMost = true;
JARVIS.Speak("expanding");
break;
case "exit fullscreen":
FormBorderStyle = FormBorderStyle.Sizable;
WindowState = FormWindowState.Normal;
TopMost = false;
break;
case "switch window":
SendKeys.Send("%{TAB " + count + "}");
count += 1;
break;
case "out of the way":
if (WindowState == FormWindowState.Normal || WindowState == FormWindowState.Maximized)
{
WindowState = FormWindowState.Minimized;
JARVIS.Speak("My apologies");
}
break;
case "come back":
if (WindowState == FormWindowState.Minimized)
{
JARVIS.Speak("Alright?");
WindowState = FormWindowState.Normal;
}
break;
case "show commands":
string[] commands = (File.ReadAllLines(@"C:\Users\Ashwini\Desktop\Jarvis\Jarvis\bin\Debug\commands.txt"));
JARVIS.Speak("Very well");
lstCommands.Items.Clear();
lstCommands.SelectionMode = SelectionMode.None;
lstCommands.Visible = true;
foreach (string command in commands)
{
lstCommands.Items.Add(command);
}
break;
case "hide listbox":
lstCommands.Visible = false;
break;
}
}
private void StopWindow()
{
}
}
}
使用系统;
使用System.IO;
使用系统语音识别;
使用系统、语音、合成;
使用System.Windows.Forms;
名称空间Jarvis
{
公共部分类Form1:Form
{
SpeechRecognitionEngine_recognizer=新建SpeechRecognitionEngine();
SpeechSynthesizer JARVIS=新SpeechSynthesizer();
字符串QEvent;
字符串窗口;
双定时器=10;
整数计数=1;
随机rnd=新随机();
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
_recognizer.setInputOdeFaultAudioDevice();
_recognizer.LoadGrammar(新语法(新语法生成器(新选项)(File.ReadAllLines(@“C:\Users\Ashwini\Desktop\Jarvis\Jarvis\bin\Debug\commands.txt“)));
_recognizer.SpeechRecognized+=新事件处理程序(_recognizer_SpeechRecognized);
_识别器.RecognizeAsync(RecognizeMode.Multiple);
}
void _recognizer _SpeechRecognized(对象发送方,SpeechRecognizedEventArgs e)
{
int ranNum=rnd.Next(1,10);
字符串语音=e.Result.Text;
开关(语音)
{
案例“你好”:
案例“你好,贾维斯”:
如果(ranNum<6){JARVIS.Speak(“你好,先生”);}
如果(ranNum>5){JARVIS.Speak(“Hello”);}
打破
案例“再见”:
案例“再见贾维斯”:
案例“结束”:
案例“close jarvis”:
JARVIS.Speak(“直到下一次”);
Close();
打破
“jarvis”案:
如果(ranNum<5){QEvent=”“;JARVIS.Speak(“是的先生”);}
如果(ranNum>4){QEvent=”“;JARVIS.Speak(“Yes?”);}
打破
//网站
案例“开放谷歌”:
系统.诊断.进程.启动(“https://www.google.com/");
打破
案例“打开我的facebook”:
系统.诊断.进程.启动(“https://www.facebook.com/");
打破
案例“打开gmail”:
系统.诊断.进程.启动(“https://www.google.com/gmail/");
打破
//SHELL命令
案例“打开此电脑”:
系统.诊断.过程.启动(“本PC”);
JARVIS.Speak(“装载”);
打破
案例“打开我的文件夹”:
系统.诊断.过程.启动(“F:”);
JARVIS.Speak(“装载”);
打破
//关闭程序
案例“关闭此电脑”:
ProcWindow=“这台电脑”;
停止窗口();
打破
//白天的情况
案例“现在几点了”:
DateTime now=DateTime.now;
string time=now.GetDateTimeFormats('t')[0];
贾维斯说(时间);
打破
案例“今天是星期几”:
JARVIS.Speak(DateTime.Today.ToString(“dddd”);
打破
案例“日期是什么时候”:
案例“今天是什么日子”:
JARVIS.Speak(DateTime.Today.ToString(“dd-MM-yyyy”);
打破
//其他命令
案例“全屏显示”:
FormBorderStyle=FormBorderStyle.无;
WindowState=FormWindowState.Maximized;
最顶端=真;
JARVIS.Speak(“扩展”);
打破
案例“退出全屏”:
FormBorderStyle=FormBorderStyle.sizeable;
WindowState=FormWindowState.Normal;
最顶端=假;
打破
案例“切换窗口”:
SendKeys.Send(“%{TAB”+count+”}”);
计数+=1;
打破
案例“让路”:
如果(WindowsState==FormWindowsState.Normal | | WindowsState==FormWindowsState.Maximized)
{
WindowState=FormWindowState.Minimized;
JARVIS.说话(“我的道歉”);
}
打破
“回来”一案:
if(WindowState==FormWindowState.Minimized)
{
贾维斯,说(“好吗?”);
WindowState=FormWindowState.Normal;
}
打破
案例“显示命令”:
string[]commands=(File.ReadAllLines(@“C:\Users\Ashwini\Desktop\Jarvis\Jarvis\bin\Debug\commands.txt”);
贾维斯:说得(“非常好”);
lstCommands.Items.Clear();
lstCommands.SelectionMode=SelectionMode.None;
lstCommands.Visible=true;
法罗群岛
Jarvis.Speak("this is what Jarvis will say after a command is spoken");
Jarvis.SpeakAsync("this is what Jarvis will say after a command is spoken");