3. We all know about Cortana
She does
•Call Hubby, mobile
•Text Hubby hi sweety
•Change my 3 pm appointment to 4
•Next time I’m at the Microsoft, remind me to meet Wela
•Take note: left my car on level 4
•Wake up me in 20 minutes
•Play Hariharan
•Find cheap pizza restaurant near me
•Do I need an umbrella
9. EXAMPLE scenario
Me : Set colour to Red
Cortana : Setting colour to Red
[Win 8 & WP apps shows Red colour background]
Me : Set colour to Blue
Cortana : Settings colour to Blue
[Win 8 & WP apps shows Red colour background]
10. REAL LIFE scenario
Me : Switch on bulb 1
Cortana : Switching bulb 1 on
[One bulb in the room gets light]
Me : Switch off bulb 1
Cortana : Switching bulb 1 off
[One bulb in the room gets off from light]
Me : Switch off bulb 1
Cortana : YAKO!! Its already off
18. <?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
<CommandSet xml:lang="en-us" Name="englishCommands">
<CommandPrefix>MSDN</CommandPrefix>
<Example>How do I add Voice Commands to my application</Example>
<Command Name="FindText">
<Example>Find Install Voice Command Sets</Example>
<ListenFor>Search</ListenFor>
<ListenFor>Search for {dictatedSearchTerms}</ListenFor>
<ListenFor>Find</ListenFor>
<ListenFor>Find {dictatedSearchTerms}</ListenFor>
<Feedback>Search on MSDN</Feedback>
<Navigate Target="MainPage.xaml" />
</Command>
<Command Name="nlpCommand">
<Example>How do I add Voice Commands to my application</Example>
<ListenFor>{dictatedVoiceCommandText}</ListenFor>
<Feedback>Starting MSDN...</Feedback>
<Navigate Target="MainPage.xaml" />
</Command>
<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation">
<Subject>MSDN</Subject>
</PhraseTopic>
<PhraseTopic Label="dictatedSearchTerms" Scenario="Search">
<Subject>MSDN</Subject>
</PhraseTopic>
</CommandSet>
</VoiceCommands>
19. private async void
// SHOULD BE PERFORMED UNDER TRY/CATCH
Uri new ms-appx:///vcd.xml UriKind.Absolute
await
// Please note that VoiceCommandService ends with WP8.1 (End of Silverlight era)
// (ie) No more .xap’s after WP8.1. Only .appx’s
Windows Phone Silverlight Apps on Windows Phone 8.1
Windows Runtime Apps on Windows Phone 8.1
private async void
// SHOULD BE PERFORMED UNDER TRY/CATCH
Uri uriVoiceCommands = new Uri("ms-appx:///vcd.xml", UriKind.Absolute);
StorageFile file = await
StorageFile.GetFileFromApplicationUriAsync(uriVoiceCommands);
await VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(file);
// No need to define Capabilities in app manifest
20.
21. // Windows Phone Silverlight App, in MainPage.xaml.cs
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)
{
string recoText = null; // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands"
NavigationContext.QueryString.TryGetValue("reco", out recoText);
string voiceCommandName = null; // Which command was recognized in the VCD.XML file? e.g. "FindText"
NavigationContext.QueryString.TryGetValue("voiceCommandName", out voiceCommandName);
string searchTerms = null;
// What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voice Commands"
NavigationContext.QueryString.TryGetValue("dictatedSearchTerms", out searchTerms);
switch (voiceCommandName) // What command launched the app?
{
case "FindText":
HandleFindText(searchTerms);
break;
case "nlpCommand":
HandleNlpCommand(recoText);
break;
}
}
}
22.
23. // Windows Runtime App on Windows Phone 8.1, inside OnActivated override in App class
if (args.Kind == ActivationKind.VoiceCommand)
{
VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;
string voiceCommandName = vcArgs.Result.RulePath.First();
// What command launched the app?
switch (voiceCommandName) // Navigate to right page for the voice command
{
case "FindText": // User said "find" or "search"
rootFrame.Navigate(typeof(MSDN.FindText), vcArgs.Result);
break;
case "nlpCommand": // User said something else
rootFrame.Navigate(typeof(MSDN.NlpCommand), vcArgs.Result);
break;
}
}