<?xml version="1.0" encoding="utf-8"?> <VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">   <CommandSet xml:lang="en-us">     <CommandPrefix>tickets</CommandPrefix>     <Example>show tonight's events at Olympia</Example>      <Command Name="showEventsAt">       <Example>show tonight's events at Olympia</Example>       <ListenFor> [Show] {eventsViews} at {eventsLocations} </ListenFor>       <Feedback> Showing {eventsViews} at {eventsLocations} </Feedback>       <Navigate Target="HomePage.xaml"/>     </Command>      <Command Name="showEventsFrom">       <Example>show tonight's events from Shaka Ponk</Example>       <ListenFor> [Show] {eventsViews} from {eventsArtists} </ListenFor>       <Feedback> Showing {eventsViews} from {eventsArtists} </Feedback>       <Navigate Target="HomePage.xaml"/>     </Command>      <PhraseList Label="eventsViews">       <Item> tonight's events </Item>       <Item> best sellers </Item>     </PhraseList>      <PhraseList Label="eventsLocations">       <Item> Olympia </Item>       <Item> Bercy </Item>     </PhraseList>      <PhraseTopic Label="eventsArtists" Scenario="Natural Language">       <Subject>Music</Subject>       <Subject>Artist</Subject>     </PhraseTopic>   </CommandSet>    <!-- Other CommandSets for other languages --> </VoiceCommands>

private async void RegisterVoiceCommands() {     Uri uriVoiceCommands = new Uri("ms-appx:///vcd.xml", UriKind.Absolute));     await VoiceCommandService.InstallCommandSetsFromFileAsync(uriVoiceCommands); }

Prérequis: N’oubliez pas d’activer les capacités ID_CAP_SPEECH_RECOGNITION, ID_CAP_MICROPHONE, et ID_CAP_NETWORKING dans le fichier WMAppManifest.xml. 

Projet Windows Runtime 8.1 (Application Universelle) :
private async void RegisterVoiceCommands() {     Uri uriVoiceCommands = new Uri("ms-appx:///vcd.xml", UriKind.Absolute);     StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uriVoiceCommands);     await VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(file); }

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {   base.OnNavigatedTo(e);    // Is this a new activation or a resurrection from tombstone?   if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)   {      // Was the app launched using a voice command?     if (NavigationContext.QueryString.ContainsKey("voiceCommandName"))     {        // If so, get the name of the voice command.       string voiceCommandName          = NavigationContext.QueryString["voiceCommandName"];        // Define app actions for each voice command name.       switch (voiceCommandName)       {         case "showWidgets":           string viewWidget = NavigationContext.QueryString["widgetViews"];                               // Add code to display specified widgets.           break;           // Add cases for other voice commands.          default:            // There is no match for the voice command name.           break;       }     }   } }
 
Code App.xaml.cs
protected override void OnActivated(IActivatedEventArgs args) {     base.OnActivated(args);      Frame rootFrame = Window.Current.Content as Frame;      // Was the app activated by a voice command?     if (args.Kind == ActivationKind.VoiceCommand)     {         var commandArgs = args as VoiceCommandActivatedEventArgs;         SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;          // If so, get the name of the voice command, the actual text spoken, and the value of Command/Navigate@Target.         string voiceCommandName = speechRecognitionResult.RulePath[0];         string textSpoken = speechRecognitionResult.Text;         string navigationTarget = speechRecognitionResult.SemanticInterpretation.Properties["NavigationTarget"][0];          switch (voiceCommandName)         {             case "showEventsAt":                 rootFrame.Navigate(typeof(HomePage), commandArgs.Result);                 break;              case "showEventsFrom":                 rootFrame.Navigate(typeof(HomePage), commandArgs.Result);                 break;              // Cases for other voice commands.             default:                 // There is no match for the voice command name.                 break;         }     } }
Code HomePage.xaml.cs
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) {     base.OnNavigatedTo(e);      ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);     RegisterVoiceCommands();      // Get recognition result from parameter passed in frame.Navigate call     SpeechRecognitionResult speechRecognitionResult = e.Parameter as SpeechRecognitionResult;      if (speechRecognitionResult != null)     {         string commandMode = speechRecognitionResult.SemanticInterpretation.Properties["commandMode"][0];          if (commandMode == "voice") // Did the user speak or type the command?         {             //SpeakText(audioPlayer, String.Format("MSDN app heard you say {0}", vcResult.Text));             HandleCommand(speechRecognitionResult);         }         else if (commandMode == "text")         {             //messageTextBox.Text = string.Format("Working on your request \"{0}\"", vcResult.Text);             HandleCommand(speechRecognitionResult);         }     }      SongkickService service = new SongkickService();     ContentResponse response = await service.EventSearch(48.856930, 2.341200);      lstLocations.ItemsSource = response.resultsPage.results.events; }  private void HandleCommand(SpeechRecognitionResult speechRecognitionResult) {     string voiceCommandName = speechRecognitionResult.RulePath[0];     string textSpoken = speechRecognitionResult.Text;     string navigationTarget = speechRecognitionResult.SemanticInterpretation.Properties["NavigationTarget"][0];      string eventsViews = speechRecognitionResult.SemanticInterpretation.Properties["eventsViews"][0];          switch (voiceCommandName)     {         case "showEventsAt":             string eventsAt = speechRecognitionResult.SemanticInterpretation.Properties["eventsLocations"][0];             break;          case "showEventsFrom":             string eventsFrom = speechRecognitionResult.SemanticInterpretation.Properties["eventsArtists"][0];             break;          // Cases for other voice commands.         default:             // There is no match for the voice command name.             break;     } }