void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (!CurrentState.config.isVoiceEnable) { return; } try { if (isRecognizing) { return; } if (e.Result.Confidence < 0.85) { return; } int NavigationNum = -1; isRecognizing = true; BossCommand selCmd = BossCommand.NoCommand; if (Perintah.ContainsKey(e.Result.Text)) { selCmd = Perintah[e.Result.Text]; } if (e.Result.Semantics != null && e.Result.Semantics.Count != 0) { if (e.Result.Semantics.ContainsKey("navigation")) { if (e.Result.Semantics["navigation"].Value.ToString().Contains("chapter")) { selCmd = BossCommand.GoToChapter; } else if (e.Result.Semantics["navigation"].Value.ToString().Contains("item")) { selCmd = BossCommand.GoToItem; } else { selCmd = BossCommand.LoadBookmark; } // Checks whether a step has been specified. if (e.Result.Semantics.ContainsKey("values")) { if (!int.TryParse(e.Result.Semantics["values"].Value.ToString(), out NavigationNum)) { return; } } } } if (selCmd == BossCommand.NoCommand) { return; } switch (selCmd) { case BossCommand.Read: //speechSynthesizer.SpeakAsync("Ok sir"); PlayBtn_Click(null, null); break; case BossCommand.Stop: StopBtn_Click(null, null); //speechSynthesizer.SpeakAsync("I have stopped the reciter"); break; case BossCommand.Exit: StopBtn_Click(null, null); speechSynthesizer.Speak("Turning off the application"); Application.Current.Shutdown(); break; case BossCommand.NextChapter: GoToNextChapter(null, null); break; case BossCommand.PrevChapter: GoToPrevChapter(null, null); break; case BossCommand.NextItem: if (CurrentState.isPlaying) { StopBtn_Click(null, null); } NextItem(false); break; case BossCommand.PrevItem: if (CurrentState.isPlaying) { StopBtn_Click(null, null); } PreviousItem(false); break; case BossCommand.GoToItem: if (NavigationNum > 0 && NavigationNum <= CurrentState.TotalHadith) { CurrentState.HadithNo = NavigationNum; StopBtn_Click(null, null); if (CurrentState.CtlContent.selBefore > -1) { CurrentState.CtlContent.SetItemHadith(CurrentState.CtlContent.selBefore, Brushes.White, false, false); } CurrentState.CtlContent.SetItemHadith(CurrentState.HadithNo - 1, Brushes.Orange, true, false); } break; case BossCommand.GoToChapter: if (NavigationNum >= CurrentState.CtlChapter.MinChapter && NavigationNum <= CurrentState.CtlChapter.MaxChapter) { if (CurrentState.isPlaying) { StopBtn_Click(null, null); } CurrentState.CtlChapter.GoToSpecificItem(NavigationNum); //LoadChapterByIndex(NavigationNum); } break; case BossCommand.VolumeUp: if (CurrentState.config.Volume + 0.2 <= MaxVolume) { VolumeSlider.Value = CurrentState.config.Volume + 0.2; } else { VolumeSlider.Value = MaxVolume; } break; case BossCommand.VolumeDown: if (CurrentState.config.Volume - 0.2 >= MinVolume) { VolumeSlider.Value = (CurrentState.config.Volume - 0.2); } else { VolumeSlider.Value = (MinVolume); } break; case BossCommand.ZoomIn: if (CurrentState.config.VerseSize + 2 <= MaxVerseSize) { FontSlider.Value = CurrentState.config.VerseSize + 2; } else { FontSlider.Value = (MaxVerseSize); } break; case BossCommand.ZoomOut: if (CurrentState.config.VerseSize - 2 >= MinVerseSize) { FontSlider.Value = (CurrentState.config.VerseSize - 2); } else { FontSlider.Value = (MinVerseSize); } break; case BossCommand.AddBookmark: AddBookmark(false); speechSynthesizer.SpeakAsync("bookmark added"); break; case BossCommand.LoadBookmark: var res = CurrentState.CtlBookmark.LoadBookmark(NavigationNum); if (!res) { speechSynthesizer.SpeakAsync(string.Format("bookmark {0} not found", NavigationNum)); } break; case BossCommand.OpenBookmark: if (!ExpanderBookmark.IsExpanded) { ExpanderBookmark.IsExpanded = true; } break; } //speechSynthesizer.Dispose(); } catch { } finally { isRecognizing = false; } }
void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (!CurrentState.CtlSetting.isVoiceEnable) { return; } try { if (isRecognizing) { return; } if (e.Result.Confidence < 0.85) { return; } int NavigationNum = -1; isRecognizing = true; BossCommand selCmd = BossCommand.NoCommand; if (Perintah.ContainsKey(e.Result.Text)) { selCmd = Perintah[e.Result.Text]; } if (e.Result.Semantics != null && e.Result.Semantics.Count != 0) { if (e.Result.Semantics.ContainsKey("navigation")) { if (e.Result.Semantics["navigation"].Value.ToString().Contains("chapter")) { selCmd = BossCommand.GoToChapter; } else if (e.Result.Semantics["navigation"].Value.ToString().Contains("verse")) { selCmd = BossCommand.GoToVerse; } else { selCmd = BossCommand.LoadBookmark; } // Checks whether a step has been specified. if (e.Result.Semantics.ContainsKey("values")) { if (!int.TryParse(e.Result.Semantics["values"].Value.ToString(), out NavigationNum)) { return; } } } } if (selCmd == BossCommand.NoCommand) { return; } switch (selCmd) { case BossCommand.Read: //speechSynthesizer.SpeakAsync("Ok sir"); PlayBtn_Click(null, null); break; case BossCommand.Stop: StopBtn_Click(null, null); //speechSynthesizer.SpeakAsync("I have stopped the reciter"); break; case BossCommand.Exit: StopBtn_Click(null, null); speechSynthesizer.Speak("Turning off the application"); Application.Current.Shutdown(); break; case BossCommand.NextSurah: NextBtn_Click(null, null); break; case BossCommand.PrevSurah: PrevBtn_Click(null, null); break; case BossCommand.NextVerse: if (CurrentState.isPlaying) { StopBtn_Click(null, null); } NextVerse(false); break; case BossCommand.PrevVerse: if (CurrentState.isPlaying) { StopBtn_Click(null, null); } PreviousVerse(false); break; case BossCommand.GoToVerse: if (NavigationNum > 0 && NavigationNum <= CurrentState.TotalAyah) { CurrentState.Ayah = NavigationNum; StopBtn_Click(null, null); if (CurrentState.CtlAyah.selBefore > -1) { CurrentState.CtlAyah.SetItemAyah(CurrentState.CtlAyah.selBefore, Brushes.White, false, false); } CurrentState.CtlAyah.SetItemAyah(CurrentState.Ayah - 1, Brushes.Red, true, false); } break; case BossCommand.GoToChapter: if (NavigationNum >= CurrentState.CtlSurah.MinSurah && NavigationNum <= CurrentState.CtlSurah.MaxSurah) { if (CurrentState.isPlaying) { StopBtn_Click(null, null); } LoadSpecificSurah(NavigationNum); } break; case BossCommand.VolumeUp: if (CurrentState.CtlSetting.Volume + 0.2 <= ListSetting.MaxVolume) { CurrentState.CtlSetting.setVolume(CurrentState.CtlSetting.Volume + 0.2); } else { CurrentState.CtlSetting.setVolume(ListSetting.MaxVolume); } break; case BossCommand.VolumeDown: if (CurrentState.CtlSetting.Volume - 0.2 >= ListSetting.MinVolume) { CurrentState.CtlSetting.setVolume(CurrentState.CtlSetting.Volume - 0.2); } else { CurrentState.CtlSetting.setVolume(ListSetting.MinVolume); } break; case BossCommand.ZoomIn: if (CurrentState.CtlSetting.VerseSize + 2 <= ListSetting.MaxVerseSize) { CurrentState.CtlSetting.setVerseSize(CurrentState.CtlSetting.VerseSize + 2); } else { CurrentState.CtlSetting.setVerseSize(ListSetting.MaxVerseSize); } break; case BossCommand.ZoomOut: if (CurrentState.CtlSetting.VerseSize - 2 >= ListSetting.MinVerseSize) { CurrentState.CtlSetting.setVerseSize(CurrentState.CtlSetting.VerseSize - 2); } else { CurrentState.CtlSetting.setVerseSize(ListSetting.MinVerseSize); } break; case BossCommand.AddBookmark: AddBookmark(false); speechSynthesizer.SpeakAsync("bookmark added"); break; case BossCommand.LoadBookmark: var res = CurrentState.CtlBookmark.LoadBookmark(NavigationNum); if (!res) { speechSynthesizer.SpeakAsync(string.Format("bookmark {0} not found", NavigationNum)); } break; case BossCommand.OpenBookmark: if (!ExpanderBookmark.IsExpanded) { ExpanderBookmark.IsExpanded = true; } break; } //speechSynthesizer.Dispose(); } catch { } finally { isRecognizing = false; } }