- Natural interaction with your application
- Grammar-based
- Requires internet connection
- Default dictation grammar for free-text and web-search are included in WP8
- Custom grammar can be defined in two ways:
– Programmatic list grammar (array of strings)– XML grammar leveraging on Speech Recognition Grammar Specification (SRGS) 1.0
- Default dictation grammar
private async void ButtonWeatherSearch_Click(object sender, RoutedEventArgs e)
{
// Add the pre-defined web search grammar to the grammar set.
SpeechRecognizerUI recoWithUI = new SpeechRecognizerUI();
recoWithUI.Recognizer.Grammars.AddGrammarFromPredefinedType ("weatherSearch",
SpeechPredefinedGrammar.WebSearch);
// Display text to prompt the user's input.
recoWithUI.Settings.ListenText = "Say what you want to search for";
// Display an example of ideal expected input.
recoWithUI.Settings.ExampleText = @"Ex. 'weather for London'";
// Load the grammar set and start recognition.
SpeechRecognitionUIResult result = await recoWithUI.RecognizeWithUIAsync();
}
- Programmatic list grammar
private async void ButtonSR_Click(object sender, RoutedEventArgs e)
{
SpeechRecognizerUI recoWithUI = new SpeechRecognizerUI();
// You can create this string dynamically, for example from a movie queue.
string[] movies = { "Play The Cleveland Story", "Play The Office", "Play Psych", "Play Breaking Bad", "Play Valley of the Sad", "Play Shaking Mad" };
// Create a grammar from the string array and add it to the grammar set.
recoWithUI.Recognizer.Grammars.AddGrammarFromList("myMovieList", movies);
// Display an example of ideal expected input.
recoWithUI.Settings.ExampleText = @"ex. 'Play New Mocumentaries'";
// Load the grammar set and start recognition.
SpeechRecognitionUIResult result = await recoWithUI.RecognizeWithUIAsync();
// Play movie given in result.Text
}
- XML grammar
private async void ButtonSR_Click(object sender, EventArgs e){
// Initialize objects ahead of time to avoid delays when starting recognition.
SpeeechRecognizerUI recoWithUI = new SpeechRecognizerUI();
// Initialize a URI with a path to the SRGS-compliant XML file.
Uri orderPizza = new Uri("ms-appx:///OrderPizza.grxml", UriKind.Absolute);
// Add an SRGS-compliant XML grammar to the grammar set.
recoWithUI.Recognizer.Grammars.AddGrammarFromUri("PizzaGrammar", orderPizza);
// Preload the grammar set.
await recoWithUI.Recognizer.PreloadGrammarsAsync();
// Display text to prompt the user's input.
recoWithUI.Settings.ListenText = "What kind of pizza do you want?";
// Display an example of ideal expected input.
recoWithUI.Settings.ExampleText = "Large combination with Italian sausage";
SpeechRecognitionUIResult recoResult = await recoWithUI.RecognizeWithUIAsync();
}
No comments:
Post a Comment