0
我有一个小型的声音指挥程序,我正在努力,并且我想让它在给定某些命令时要求确认......就像“嘿计算机,关闭程序”,然后是口头问题“你确定吗?”。之后回应我的口头答复;是或否。我对c#相当陌生,找不到任何相关的东西。下面的代码是语音命令的示例,我已经配置:如何让我的程序在使用语音命令时要求确认?
private void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text)
{
case "hey computer, start spotify":
synthesizer.SelectVoiceByHints(VoiceGender.Female);
synthesizer.SpeakAsync("starting SPOTteFY");
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string extentionToPath = "Spotify\\Spotify.exe";
string finalPath = Path.Combine(appDataPath, extentionToPath);
Process.Start(finalPath);
//Process.Start("C:\\Users\\Danny\\AppData\\Roaming\\Spotify\\Spotify.exe");
break;
case "hey computer, start chrome":
synthesizer.SelectVoiceByHints(VoiceGender.Female);
synthesizer.SpeakAsync("Starting Chrome");
Process.Start("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
break;
case "hey computer, new tab":
SendKeys.Send("^t");
break;
case "hey computer, close program":
synthesizer.SelectVoiceByHints(VoiceGender.Female);
synthesizer.SpeakAsync("Closing program");
SendKeys.Send("%{F4}");
break;
case "next song please":
keybd_event(VK_MEDIA_NEXT_TRACK, 0, KEYEVENTF_EXTENTEDKEY, IntPtr.Zero);
break;
case "stop song please":
keybd_event(VK_MEDIA_PLAY_PAUSE, 0, KEYEVENTF_EXTENTEDKEY, IntPtr.Zero);
break;
case "hey computer, start netflix":
synthesizer.SelectVoiceByHints(VoiceGender.Female);
synthesizer.SpeakAsync("Starting Netflix");
System.Diagnostics.Process.Start("https://www.netflix.com/browse");
break;
case "hey computer, pause netflix":
SendKeys.Send(" ");
break;
case "hey computer, start reddit":
synthesizer.SelectVoiceByHints(VoiceGender.Female);
synthesizer.SpeakAsync("Starting reddit");
System.Diagnostics.Process.Start("https://www.reddit.com");
break;
case "hey computer, show me the news":
synthesizer.SelectVoiceByHints(VoiceGender.Female);
synthesizer.SpeakAsync("Showing you what's going on");
System.Diagnostics.Process.Start("http://nu.nl");
break;
case "hey computer, hide yourself":
this.WindowState = FormWindowState.Minimized;
break;
}
}