Cookie CSS

Saturday, February 6, 2016

Using Cortana in Windows 10 to Automate Skype For Business Part III

This week I will continue this series, and focus on how to handle the voice prompts that Cortana will send to our app.  Most of the examples on the web show you how to launch your from the background on a voice prompt, but we are going to focus more on a real-time interaction between the user's voice, Cortana, and our application.



The way I do this is to drop some code the App.xaml.cs, specifically in the OnActivated method.

 protected async override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);
            string section = string.Empty;

            if (args.Kind == ActivationKind.VoiceCommand)
            {
                VoiceCommandActivatedEventArgs voiceArgs = args as VoiceCommandActivatedEventArgs;
                SpeechRecognitionResult speechRecognitionResult = voiceArgs.Result;

                System.Diagnostics.Debug.WriteLine(speechRecognitionResult.Text);

 if (speechRecognitionResult.Text.Contains("status"))
                {
                    string a = "";
                    string ActivToPub = "";

                    a = this.SemanticInterpretation("status", speechRecognitionResult);

                    if (a == "Appear Away")
                    {
                        ActivToPub = "Away";
                    }

                    if (a == "Off Work")
                    {
                        ActivToPub = "off-work";
                    }

                   //Here is where my code talks to our application tell it to change the status of your uri, sending the availability a (available, busy, do not disturb, appear away, be right back, off work), and the optional activity if it is one of the subsets of away.

                }

}

The first thing to note is when to trigger, we look to see if the program was activated by a voice command.  Next we pull the arguments specifically looking for the voice result.  Once we have the result we check to see if it contains one of our commands.  In my case here, we are looking for "change my status to ", so we look to see if the text contains "status" as our match condition.  Once we have that we look in our xml file and make sure the following uttered status matches of those choices ;

 <PhraseList Label="status">
      <Item> Busy </Item>
      <Item> Do No Disturb </Item>
      <Item> Available </Item>
      <Item> Be Right Back </Item>
      <Item> Appear Away </Item>
      <Item> Off Work </Item>
    </PhraseList>

So in our software that talks to the Lync or Skype for Business client we the simply implement the function to change the status.  I hope this series gave you some idea of how to the all of the building blocks together and was useful.

Doug Routledge, C# Lync, Skype for Business, SQL, Exchange, UC Developer  BridgeOC
Twitter - @droutledge @ndbridge

No comments:

Post a Comment

Any spam comments will be deleted and your user account will be disabled.