tdc 2014 - cortana

13
Thiago Mônaco MVP Windows Plataform Development Cortana Me

Upload: tmonaco

Post on 12-Jan-2015

132 views

Category:

Technology


0 download

DESCRIPTION

Palestra sobre Windows Phone 8.1 - Cortana

TRANSCRIPT

Page 1: TDC 2014 - Cortana

Thiago MônacoMVP Windows Plataform Development

Cortana Me

Page 2: TDC 2014 - Cortana

Hi Cortana.O que você pode fazer?Como você trabalha com as Apps?Como posso fazer isso com minha App?

Agenda

Page 3: TDC 2014 - Cortana

Cortana: O que você pode fazer?

REMEMBER

COMMUNICATE

FIND

People

Places

Calendar

Information

Page 4: TDC 2014 - Cortana

Cortana: What Can You Do?Phone

MessagingCalendarRemindersNotes

Alarms

Music

Places

Search

Cortana: What Can You Do?

Your App goes here

Page 5: TDC 2014 - Cortana

Integre com Cortana em 3 Passos:

Crie Voice Command Definition(s)

Registre o XML de VCD XML no Startup da App

Trate as Ativações por Comando de Voz

Page 6: TDC 2014 - Cortana

Passo 1

Passo 2

Passo 3

<?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>

Crie Voice Command Definition(s)

Page 7: TDC 2014 - Cortana

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

Windows Phone Silverlight Apps on Windows Phone 8.1

Windows Runtime Apps on Windows Phone 8.1

private async void RegisterVoiceCommands(){ // 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);}

Passo 1

Passo 2

Passo 3

Registre o XML de VCD XML no Startup da App

Passo 1

Passo 2

Page 8: TDC 2014 - Cortana

Step 2Passo 2

Passo 1

Passo 3Passo 3

Trate as Ativações por Comando de Voz

VCD Commands and Targets

YourPage.xamlSYSTEM

Silverlight App

System launches app on page specified by Target

❷ Page code maps commands (intents) into actions

Step 2Passo 2

Passo 1

Passo 3Passo 3

Page 9: TDC 2014 - Cortana

// 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; } }}

Trate as Ativações por Comando de Voz

Step 2Passo 2

Passo 1

Passo 3Passo 3

Page 10: TDC 2014 - Cortana

VCD Commands and Targets

Trate as Ativações por Comando de VozWindows Runtime App

System tells code in App class what command and target were used❶

SYSTEMApp class

Code in App class navigates to page❷Page code maps commands (intents) into actions❸

YourPage.xaml

Step 2Passo 2

Passo 1

Passo 3Passo 3

Page 11: TDC 2014 - Cortana

// 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; }}

Trate as Ativações por Comando de Voz

Step 2Passo 2

Passo 1

Passo 3Passo 3

Page 12: TDC 2014 - Cortana

// Windows Runtime App on Windows Phone 8.1, inside OnNavigatedTo in FindText.xaml.cs protected override void OnNavigatedTo(NavigationEventArgs e){ // Get recognition result from parameter passed in frame.Navigate call SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult;

if (vcResult!=null) { // What did the user say? e.g. MSDN, "Find Windows Phone Voice Commands" string recoText = vcResult.Text;

// Store the semantics dictionary for later use IReadOnlyDictionary<string,IReadOnlyList<string>> semantics = vcResult.SemanticInterpretation.Properties;

string voiceCommandName = vcResult.RulePath.First();

if (voiceCommandName == "FindText") { // What did the user say, for named phrase topic or list "slots"? e.g. "Windows Phone Voice Commands" if (semantics.ContainsKey("dictatedSearchTerms")) { HandleFindTextWithSearchTerms(semantics["dictatedSearchTerms"][0]); } else { HandleNoSearchTerms(); } } // Else handle other voice commands } navigationHelper.OnNavigatedTo(e)}

Trate as Ativações por Comando de Voz

Step 2Passo 2

Passo 1

Passo 3Passo 3

Page 13: TDC 2014 - Cortana

// Windows Runtime App on Windows Phone 8.1, inside OnNavigatedTo in NlpCommand.xaml.cs protected override void OnNavigatedTo(NavigationEventArgs e){ base.OnNavigatedTo(e);

// Get recognition result from parameter passed in frame.Navigate call SpeechRecognitionResult vcResult = e.Parameter as SpeechRecognitionResult; // Check for null!

string commandMode = vcResult.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));

HandleNlpCommand(vcResult); } else if(commandMode=="text") { messageTextBox.Text = string.Format("Working on your request \"{0}\"", vcResult.Text);

HandleNlpCommand(vcResult); }}

Trate as Ativações por Comando de Voz

Step 2Passo 2

Passo 1

Passo 3Passo 3