Exemple #1
0
        private async void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            AppBarButton btn = sender as AppBarButton;

            if (btn.Label == "save")
            {
                App.ViewModel.AddNewEntry(App.ViewModel.CurrentEntry);
                await helper.DisplayMessage("Saved!");

                this.Frame.GoBack();
            }
            else
            {
                PromptUserToSpeak();
            }
        }
Exemple #2
0
        private async void PromptUserToSpeak()
        {
            string displayMessage = string.Empty;

            try
            {
                if (helper == null)
                {
                    helper = new SpeechHelper();
                    await helper.SetSpeechRecognizerPromptsAsync("What would you like to do?", "Ex: new journal entry, show last entry");
                }

                SpeechRecognitionResult recognitionResult = await helper.ShowSpeechUIAsync();

                if (recognitionResult.Status == SpeechRecognitionResultStatus.Success)
                {
                    string result       = recognitionResult.Text;
                    string voiceCommand = (result.ToLower().Contains("new journal entry") || result.ToLower().Contains("add entry")) ? "AddEntry" :
                                          (result.ToLower().Contains("dear diary")) ? "EagerEntry" :
                                          ((result.ToLower().StartsWith("view") || result.ToLower().StartsWith("show")) && result.ToLower().Contains("entry")) ? "ViewEntry" : "";

                    switch (voiceCommand)
                    {
                    case "ViewEntry":
                        this.Frame.Navigate(typeof(ViewDiaryEntry), result);
                        break;

                    case "AddEntry":
                        this.Frame.Navigate(typeof(AddDiaryEntry), "");
                        break;

                    case "EagerEntry":
                        this.Frame.Navigate(typeof(AddDiaryEntry), result);
                        break;

                    default:
                        displayMessage = "Didn't understand that. Try again.";
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                displayMessage = ex.Message;
            }

            if (!string.IsNullOrEmpty(displayMessage))
            {
                await helper.DisplayMessage(displayMessage);
            }
        }
        private async void ManageActions(string result)
        {
            if (result.Contains("first") || result.Contains("1st"))
            {
                App.ViewModel.CurrentEntry = App.ViewModel.DiaryEntries.FirstOrDefault();
            }
            else if (result.Contains("last"))
            {
                App.ViewModel.CurrentEntry = App.ViewModel.DiaryEntries.LastOrDefault();
            }
            else if (result.Contains("yesterday"))
            {
                App.ViewModel.CurrentEntry = App.ViewModel.DiaryEntries.Where(d => DateTime.Now.Subtract(d.EntryDate) >= new TimeSpan(1, 0, 0, 0)).FirstOrDefault();
                if (App.ViewModel.CurrentEntry == null)
                {
                    InitiateSpeech("You didn't record an entry yesterday.");
                }
            }
            else if (result.Contains("this week"))
            {
                App.ViewModel.CurrentEntry = App.ViewModel.DiaryEntries.Where(d => DateTime.Now.Subtract(d.EntryDate) >= new TimeSpan(7, 0, 0, 0)).FirstOrDefault();
                if (App.ViewModel.CurrentEntry == null)
                {
                    InitiateSpeech("You didn't record an entry this week.");
                }
            }
            else
            {
                if (helper == null)
                {
                    helper = new SpeechHelper();
                }

                await helper.DisplayMessage("Didn't understand that. Try again.");
            }
        }