Integrating Cortana | Part 3

Cortana

In the two previous blog posts, you should be finished of the first two steps of integrating Cortana.

So, in this blog post, you will perform the last step of integrating Cortana and the most important one which is How to Handle the voice commands.

What we did in the two past blog posts is:

  1. We Created the VCD file which contains the Voice Commands Which the user should say to Cortana.
  2. Then, we registered this VCD file on App Startup to let the System/Cortana recognize which command is activated by the user later.

And Now, we will walk through How to Handle the Voice Command when the user Activate it by saying it to Cortana,  in other words, What the action should be performed when the user say a specific Command.

Here’s a diagram of what happens to Handle a specific Voice Command.
Step3

Handle Voice Command Activation

Here’s the procedure to handle your voice commands:

  1. Open App.xaml.cs and then Override OnActivated Method and add this snippet of code:Step3 - 1
    In this step, we just tells the system when the App is Activated by Voice perform the following, which is based upon the voice command name, then navigate to a Target Page with a parameter(the result of voice command)
  2. Now, is the real step to Handle the specific Voice Command. To do this add this Code in the TargetPage.xaml.cs which is Mainpage.xaml.cs in our case.Step3 - 2
    Here, we recieved the parameter from the App.xaml.cs as a SpeechResult and a specific voice command is activated, do the following.

In this example, we are just getting a dictation of what the user says after a voice command is activated(ShowText) using SpeechRecognitionResult.SemanticInterpretation.Properties[“label of the voice command or phrase topic defined in VCD file”][index] Method.

You can Handle your commands as you want using this syntax.

 

Here’s a full Power Point Presentation of Integrating Cortana.


And Here’s the full Code Sample.
To run the sample, Call Cortana and say “MSP text hello there or whatever”
“MSP text” to activate to voice command.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s