In this blog, you will learn How to integrate Cortana into your Windows Phone 8.1 Runtime App.
But, before you integrate Cortana, you have to know Who is Cortana?
So, let me introduce Cortana to you, or actually she will 😀
Who is Cortana?
Cortana is your Digital Personal Assistant, it was developed by Microsoft for Windows Phone 8.1, Microsoft Band and it will be available in Windows 10.
Cortana was announced for the first time at Microsoft BUILD Developer Conference April 2014 and before that she was a character in Halo video game series.
If you have a Windows Phone Device, try asking Cortana “Who are you?” and “Tell me more about yourself.” 😉
Cortana’s Core Functions
Cortana has Three Core Functions:
It can make a call, send text message and text dictation task and so on.
Help the user complete the task now, or help them remember for later.
Finding content in large catalogs, from large lists, etc…
What can Cortana do?
If you have a Windows Phone Device, try asking Cortana the below commands between the double quotations.
“What’s the weather today?”
- Driving Directions
“Where am i?” “How far is…?”
- Events and Reminders
“When i leave work, remind me to stop at the gas station.”
“Tell me a joke” “Make an Impersonation”
And you can do more and more 😀
Now, we have to go into action, let’s get started to integrate Cortana 😉
Actually, you can integrate Cortana into your App within easy Three Steps:
- Create Voice Command Definition File(xml)
- Register VCD xml file on App Startup
- Handle Voice Command Activation
1. Creating Voice Command Definition File
This file will contain the commands that Cortana should recognize and you will handle these commands.
After Creating a new Windows Phone 8.1 Runtime App, follow these steps:
- In Solution Explorer, Right Click the Project and Choose Add the Add new item.
- Choose Visual C# > Voice Command Definition.
- You will find an xml file opened, and there’s a real example written, you can customize it or write your own commands.
Now, let’s understand this VCD xml file.
- Voice Commands: The root element contains 1:15 commandset element.
- Commandset: A Container for all voice commands. Has an attribute specifies the language of the commands.
- CommandPrefix: (Optional) A nickname of your App, the user can use it and then say the command, to let Cortana know what app will you target.
- Command: Intiating the App action.
- Example: Takes the Name attribute. Defines an app action that users can initiate by speaking and what users can say to initiate the action.
- ListenFor: (1:10) Contains a word or phrase that your app will recognize for this command. This may include or be a reference to a PhraseList (or PhraseTopic) element’sLabel attribute, which appears in the ListenFor element enclosed in curly braces.
- Feedback: Specifies the text that will be displayed and read back to the user when the command is recognized.
- Navigate: The Target attribute is optional and is typically used to specify the page that the app should navigate to when it launches.
- PhraseList: (Optional) One CommandSet element can contain no more than 2,000 Item elements, and 2,000 Item elements is the combined total limit across all PhraseList elements in a CommandSet.
Each Item specifies a word or phrase that can be recognized to initiate the command that references the PhraseList. The Items content may be programmatically updated from within your application. A PhraseList requires theLabel attribute, the value of which may appear—enclosed by curly braces—inside ListenFor or Feedback elements, and is used to reference thePhraseList.
- Item: One of multiple words or phrases that can be recognized to initiate a command.
- PhraseTopic: (Optional) Specifies a topic for large vocabulary recognition. The topic may specify a single (0 or 1) Scenario attribute and several (0 to 20) Subject child elements for the scenario, which may be used to improve the relevance of the recognition achieved. A PhraseTopicrequires the Label attribute, the value of which may appear—enclosed by curly braces—inside ListenFor or Feedback elements, and is used to reference the PhraseTopic.- The Scenario attribute (default “Dictation”) specifies the desired scenario for this PhraseTopic, which may optimize the underlying speech recognition of voice commands using the PhraseTopic to produce results that are better-suited to the desired context of the command. Valid values are “Natural Language”, “Search”, “Short Message”, “Dictation”, “Commands”, and “Form Filling”.- The Subject child elements specify a subject specific to the Scenario attribute of the parent PhraseTopic to further refine the relevance of speech recognition results within spoken commands using the PhraseTopic. Subjects will be evaluated in the order provided and, when appropriate, later-specified subjects will constrain earlier-specified ones. Valid inner text values are “Date/Time”, “Addresses”, “City/State”, “Person Names”, “Movies”, “Music”, and “Phone Number”. For example:
Here’s the Next Step of Integrating Cortana:
Integrating Cortana | Part 2