Friday, 6 June 2014

Speech recognition

  •  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();
}

Voice commands

• Set up your project capabilities:
– D_CAP_SPEECH_RECOGNITION,
– ID_CAP_MICROPHONE,
– ID_CAP_NETWORKING

• Create a new Voice Command Definition

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0">
  <CommandSet xml:lang="en-US">
    <CommandPrefix>Contoso Widgets</CommandPrefix>
    <Example> Show today's specials </Example>

    <Command Name="showWidgets">
      <Example> Show today's specials </Example>
      <ListenFor> [Show] {widgetViews} </ListenFor>
      <ListenFor> {*} [Show] {widgetViews} </ListenFor>
      <Feedback> Showing {widgetViews} </Feedback>
      <Navigate Target="/favorites.xaml"/>
    </Command>    

    <PhraseList Label="widgetViews">
      <Item> today's specials </Item>
      <Item> best sellers </Item>      
    </PhraseList>
  </CommandSet>
</VoiceCommands>

Install the Voice Command Definition (VCD) file

await VoiceCommandService.InstallCommandSetsFromFileAsync( new Uri("ms-appx:///ContosoWidgets.xml") );

VCD files need to be installed again when a 
backup is restored on a device.

Voice commands parameters are included in the QueryString property of the NavigationContext

"/favorites.xaml voiceCommandName=showWidgets&widgetViews=best%20sellers&reco=Contoso%20Widgets%Show%20best%20sellers"

Asterisks in ListenFor phrases are passed as “…”

– In other words, it is not possible to receive the actual text that matched the asterisk.

Speech for Windows Phone 8

  1. Voice commands
  2. Speech recognition
  3. Text-to-speech (TTS)
  4. Q&A

Wikipedia

Search results