void SearchSteamGame() { appList = new List <AppLabel>(); Log("Searching Steam Games... "); RegistryKey OurKey = Registry.CurrentUser; OurKey = OurKey.OpenSubKey(@"Software\\Valve\\Steam\\Apps", true); foreach (string keyname in OurKey.GetSubKeyNames()) { //Log("Keyname : " + Keyname); RegistryKey key = OurKey.OpenSubKey(keyname); bool installed = false; if (key.GetValue("Installed") != null) { installed = (int)(key.GetValue("Installed")) != 0; } string name = string.Empty; if (key.GetValue("Name") != null) { name = key.GetValue("Name").ToString(); } if (installed && !string.IsNullOrEmpty(name)) { Log(key.GetValue("Name").ToString() + "Added. "); AppLabel app = new AppLabel(); app.name = name; app.steamAppid = keyname; app.grammar = new List <string>(); if (calledbyName.IsChecked.Value) { app.grammar.Add(name); } appList.Add(app); } } SaveAppSettings(); Log("Searching Game Completed. "); }
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { string result = e.Result.Text; float confidence = e.Result.Confidence; //RecognizedAudio audio = e.Result.Audio; //TimeSpan start = new TimeSpan(0); //TimeSpan duration = audio.Duration - start; //string path = @"/cmd.wav"; //using (Stream outputStream = new FileStream(path, FileMode.Create)) //{ // RecognizedAudio nameAudio = audio.GetRange(start, duration); // nameAudio.WriteToWaveStream(outputStream); // outputStream.Close(); //} Log(confidence + "% > " + result + " "); if (result.IndexOf(speakerName) >= 0) { if (confidence < .94f) { return; } allowCallGame = true; synthesizer.SpeakAsync("係"); return; } bool isOpenGameCMD = false; for (int i = 0; i < openGameGammer.Length; i++) { if (result.IndexOf(openGameGammer[i]) >= 0) { isOpenGameCMD = true; break; } } // Open game if (allowCallGame && isOpenGameCMD) { if (confidence < .65f) { return; } synthesizer.SpeakAsync("Okay"); string target = result.Substring(3, result.Length - 3); AppLabel targetApp = appList[appGrammarDict[target]]; currentStatus.Text = targetApp.name; if (!string.IsNullOrEmpty(targetApp.steamAppid)) { System.Diagnostics.Process.Start("steam://run/" + targetApp.steamAppid); } else if (!string.IsNullOrEmpty(targetApp.path)) { System.Diagnostics.Process.Start(targetApp.path); } Log("[ACT] Run " + targetApp.name); allowCallGame = false; } else if (allowCallGame && result.IndexOf("關閉") >= 0) { if (confidence < .65f) { return; } Application.Current.Shutdown(); } }
private void InitSpeechRecognitionEngine() { // Create a new SpeechRecognitionEngine instance. sre = new SpeechRecognitionEngine(); // Configure the input to the recognizer. sre.SetInputToDefaultAudioDevice(); Log("=== RecognizerInfo ==="); Log(sre.RecognizerInfo.Culture.DisplayName); Log(sre.RecognizerInfo.Culture.CultureTypes.ToString()); Log(sre.RecognizerInfo.Culture.TextInfo.ToString()); Log(sre.RecognizerInfo.Description); // Create a simple grammar that recognizes "red", "green", or "blue". Choices commands = new Choices(); commands.Add(openGameGammer); Choices games = new Choices(); //games.Add(new string[] { "LoL", "pubg"}); List <string> appGrammar = new List <string>(); appGrammarDict = new Dictionary <string, int>(); for (int i = 0; i < appList.Count; i++) { AppLabel app = appList[i]; if (app.grammar != null && app.grammar.Count > 0) { foreach (string call in app.grammar) { appGrammar.Add(call); if (!appGrammarDict.ContainsKey(call)) { appGrammarDict.Add(call, i); } } } } games.Add(appGrammar.ToArray()); if (appGrammar.Count <= 0) { games.Add(new string[] { "none" }); } GrammarBuilder callgb = new GrammarBuilder(); callgb.Culture = new System.Globalization.CultureInfo(cultrue); callgb.Append(speakerName); // Create a GrammarBuilder object and append the Choices object. GrammarBuilder gb = new GrammarBuilder(); gb.Culture = new System.Globalization.CultureInfo(cultrue); gb.Append(commands); gb.Append(games); GrammarBuilder cmdgb = new GrammarBuilder(); cmdgb.Culture = new System.Globalization.CultureInfo(cultrue); cmdgb.Append("關閉"); // Create the Grammar instance and load it into the speech recognition engine. Grammar gcaller = new Grammar(callgb); sre.LoadGrammarAsync(gcaller); Grammar g = new Grammar(gb); sre.LoadGrammarAsync(g); Grammar cmdg = new Grammar(cmdgb); sre.LoadGrammarAsync(cmdg); // Register a handler for the SpeechRecognized event. sre.SpeechRecognized += sre_SpeechRecognized; // Start recognition. sre.RecognizeAsync(RecognizeMode.Multiple); Log("SpeechRecognitionEngine Loadded."); currentStatus.Text = "Hello, 我叫 " + speakerName; synthesizer.SpeakAsync(currentStatus.Text); }