in FamilyNotes/MainPage.xaml.cs [667:792]
private async void SpeechManager_PhraseRecognized(object sender, PhraseRecognizedEventArgs e)
{
Person person = e.PhraseTargetPerson;
string phrase = e.PhraseText;
CommandVerb verb = e.Verb;
string msg = String.Format("Heard phrase: {0}", phrase);
Debug.WriteLine(msg);
switch (verb)
{
case CommandVerb.Dictation:
{
// The phrase came from dictation. Now that dictation has ended, transition
// speech recognition to its previous mode (listen for command phrases or disable).
await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
FocusedNote.NoteBusinessObject.NoteText = phrase;
if ((bool)VoiceCommandButton.IsChecked)
{
EnableVoiceCommands();
}
else
{
DisableVoiceCommands();
}
FocusedNote.InputMode = NoteInputMode.Text;
});
break;
}
case CommandVerb.Create:
{
// A command for creating a note was recognized.
await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
_activeNote = CreateNote(person);
_activeNote.NoteText = "Dictate your note here!";
if (await _speechManager.SetRecognitionMode(SpeechRecognitionMode.Dictation))
{
await _speechManager.SpeakAsync("Dictate your note", _media);
FocusedNote.InputMode = NoteInputMode.Dictation;
}
else
{
FocusedNote.InputMode = NoteInputMode.Text;
}
});
break;
}
case CommandVerb.Read:
{
// The command for reading a note was recognized.
bool focusedNoteAssigned = await FocusedNoteAssigned();
if (focusedNoteAssigned)
{
await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await _speechManager.SpeakAsync(
FocusedNote.NoteBusinessObject.NoteText,
_media);
});
}
break;
}
case CommandVerb.Edit:
{
// The command for editing a note was recognized.
bool focusedNoteAssigned = await FocusedNoteAssigned();
if (focusedNoteAssigned)
{
await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
if (await _speechManager.SetRecognitionMode(SpeechRecognitionMode.Dictation))
{
await _speechManager.SpeakAsync("Dictate your note", _media);
FocusedNote.InputMode = NoteInputMode.Dictation;
}
else
{
FocusedNote.InputMode = NoteInputMode.Text;
}
});
}
break;
}
case CommandVerb.Delete:
{
// The command for deleting a note was recognized.
bool focusedNoteAssigned = await FocusedNoteAssigned();
if (focusedNoteAssigned)
{
await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
FocusedNote.OnDeleteNoteEvent();
await _speechManager.SpeakAsync("Note deleted", _media);
});
}
break;
}
case CommandVerb.Show:
{
Debug.WriteLine("SpeechManager.PhraseRecognized handler: Show TBD");
break;
}
case CommandVerb.Help:
{
// A command for spoken help was recognized.
await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await _speechManager.SpeakAsync(_helpString, _media);
});
break;
}
default:
{
Debug.WriteLine("SpeechManager.PhraseRecognized handler: Couldn't determine phrase intent");
break;
}
}
}