37
Cortana CartujaDotNet Integrando nuestra aplicación Windows Phone con Cortana

Integrando nuestra Aplicación Windows Phone con Cortana

Embed Size (px)

DESCRIPTION

Integrando una Aplicación Windows Phone con Cortana.

Citation preview

Page 1: Integrando nuestra Aplicación Windows Phone con Cortana

Cortana

CartujaDotNet

Integrando nuestra aplicación Windows Phone con Cortana

Page 2: Integrando nuestra Aplicación Windows Phone con Cortana

Javier Suárez RuizMicrosoft MVP Windows Platform Development

• Blog: http://geeks.ms/blogs/jsuarez• Email: [email protected]• Twitter: @jsuarezruiz

Page 3: Integrando nuestra Aplicación Windows Phone con Cortana

Hola, soy Cortana.¿Que puede hacer?¿Cómo integro mi App con Cortana?Consejos para una integración perfectaPreguntas y respuestas

Agenda

Page 4: Integrando nuestra Aplicación Windows Phone con Cortana

Cortana: What Can You Do?

RECORDAR

COMUNICAR

ENCONTRAR

Personas

Lugares

Calendario

Información

Page 5: Integrando nuestra Aplicación Windows Phone con Cortana

Cortana: What Can You Do?Phone

MessagingCalendarRemindersNotes

Alarms

Music

Places

Search

Cortana: What Can You Do?

Your App goes here

Page 6: Integrando nuestra Aplicación Windows Phone con Cortana

Demo 1Uso de Cortana con Apps del sistema

Page 7: Integrando nuestra Aplicación Windows Phone con Cortana

La integración con Cortana la realizamos en 3 sencillos pasos:

Crear las deficiones de los comandos de voz (VCD)

Registrar los XML VCD en el arranque de la App

Gestionar la activación desde commandos de voz

Page 8: Integrando nuestra Aplicación Windows Phone con Cortana

1º Paso

2º Paso

3º Paso

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

Crear la definición de los comandos de voz (VCD)

Page 9: Integrando nuestra Aplicación Windows Phone con Cortana

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

Crear la definición de los comandos de voz (VCD)

<CommandPrefix>MSDN</CommandPrefix>

1º Paso

2º Paso

2º Paso

Command Prefix Nombre de la Aplicación Los usuarios pueden usar el nombre para accede a la misma.

Page 10: Integrando nuestra Aplicación Windows Phone con Cortana

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

Crear la definición de los comandos de voz (VCD)

<Example>How do I add Voice Commands to my application</Example>

1º Paso

2º Paso

3º Paso

Example Ejemplo de las acciones que puede ejecutar el usuario (1º Nivel) Se les mostrará al usuario cuando el usuario pregunte “What can I do?” a

Cortana

Page 11: Integrando nuestra Aplicación Windows Phone con Cortana

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

Crear la definición de los comandos de voz (VCD)

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

1º Paso

2º Paso

3º Paso

Command Contiene…

… lo que el usuario puede preguntar a Cortana … Lo que Cortana responde … la acción de ejecutará Cortana

Page 12: Integrando nuestra Aplicación Windows Phone con Cortana

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

Crear la definición de los comandos de voz (VCD)

<Example>Find Install Voice Command Sets</Example>

1º Paso

2º Paso

3º Paso

Example Ejemplo de lo que el usuario puede preguntar a Cortana (2º Nivel) Se les mostrará al usuario cuando el usuario pregunte “What can I do?” a

Cortana

Page 13: Integrando nuestra Aplicación Windows Phone con Cortana

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

Crear la definición de los comandos de voz (VCD)

<ListenFor>Search</ListenFor><ListenFor>Search for {dictatedSearchTerms}</ListenFor><ListenFor>Find</ListenFor><ListenFor>Find {dictatedSearchTerms}</ListenFor>

1º Paso

2º Paso

3º Paso

Listen for Una o más frases Las frases pueden contener “slots” Los slots pueden ser Phrase Lists, o Phrase Topics

Page 14: Integrando nuestra Aplicación Windows Phone con Cortana

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

Crear la definición de los comandos de voz (VCD)

<Feedback>Search on MSDN</Feedback>

1º Paso

2º Paso

3º Paso

Feedback Feedback visual que se mostrará tras reconocer el commando a ejecutar y

antes de lanzar la aplicación. Puede contener referencias a slots, Ejemplo: “Search on MSDN for

{dictatedSearchTerms}”

Page 15: Integrando nuestra Aplicación Windows Phone con Cortana

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

Crear la definición de los comandos de voz (VCD)

<Navigate Target="MainPage.xaml" />

1º Paso

2º Paso

3º Paso

Navigate Acción a ejecutar Es opcional en Apps no Silverlight

Page 16: Integrando nuestra Aplicación Windows Phone con Cortana

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

Crear la definición de los comandos de voz (VCD)

<PhraseTopic Label="dictatedVoiceCommandText" Scenario="Dictation"> <Subject>MSDN</Subject></PhraseTopic>

<PhraseTopic Label="dictatedSearchTerms" Scenario="Search"> <Subject>MSDN</Subject></PhraseTopic>

1º Paso

2º Paso

3º Paso

Phrase Topic Similar a los Phrase Lists de Windows Phone 8.0 Aumentan significativamente un reconocimiento correcto

Page 17: Integrando nuestra Aplicación Windows Phone con Cortana

Demo 2Creando el archivo VCD

Page 18: Integrando nuestra Aplicación Windows Phone con Cortana

<?xml version="1.0" encoding="utf-8"?><VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0">   <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>

Crear la definición de los comandos de voz (VCD)

1º Paso

2º Paso

3º Paso

TRANSICIÓN(Se mostrará correctamente en modo de visualización)

Page 19: Integrando nuestra Aplicación Windows Phone con 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

Windows Runtime Apps

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

Step 1

2º Paso

3º Paso

Registrar el archivo XML VCD en el arranque de la App

1º Paso

2º Paso

Page 20: Integrando nuestra Aplicación Windows Phone con Cortana

Demo 3Registrando el archivo VCD en el arranque de la App

Page 21: Integrando nuestra Aplicación Windows Phone con Cortana

Step 22º Paso

1º Paso

3º Paso3º Paso

VCD Commands

Gestionar la activación desde commandos de vozWindows Runtime App

El Sistema le pasa a la clase App.xaml.cs que comando de voz ha sido ejecutado.❶

SISTEMAClase

App.xaml.cs

En código en App.xaml.cs obtiene la información y realiza la navegación correspondiente.❷En la página correspondiente se captura el parámetro enviado y se ejecuta la acción adecuada.❸

Pagina.xaml

Page 22: Integrando nuestra Aplicación Windows Phone con 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; }}

Gestionar la activación desde commandos de voz

Step 22º Paso

1º Paso

3º Paso3º Paso

Page 23: Integrando nuestra Aplicación Windows Phone con 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; }}

Gestionar la activación desde commandos de voz

// Windows Runtime App on Windows Phone 8.1, inside OnActivated override// in App class

if (args.Kind == ActivationKind.VoiceCommand)

1. args.Kind nos indica si la aplicación se active desde un comando de voz

Step 22º Paso

1º Paso

3º Paso3º Paso

Page 24: Integrando nuestra Aplicación Windows Phone con 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; }}

Gestionar la activación desde commandos de voz

VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;

// What command launched the app?string voiceCommandName = vcArgs.Result.RulePath.First();  // Navigate to right page for the voice command switch (voiceCommandName)

1. Si la App se lanza desde un comando de voz, el parámetro args es un objeto de tipo VoiceCommandActivatedEventArgs

2. Contiene un parámetro de tipo SpeechRecogntionResult

3. Podemos mediante el parámetro voiceCommandName decider que página lanzar

Step 22º Paso

1º Paso

3º Paso3º Paso

Page 25: Integrando nuestra Aplicación Windows Phone con 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; }}

Gestionar la activación desde commandos de voz // Navigate to right page for the voice command

switch (voiceCommandName) { 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;}

Pasaremos el objeto a la página para utilizarlo y ejecutar la acción deseadaStep 22º Paso

1º Paso

3º Paso3º Paso

Page 26: Integrando nuestra Aplicación Windows Phone con 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)}

Step 22º Paso

1º Paso

3º Paso3º Paso

Gestionar la activación desde commandos de voz

Page 27: Integrando nuestra Aplicación Windows Phone con 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)}

Gestionar la activación desde commandos de voz

// 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();

Ejemplo de que hacer en el método OnNavigatedTo1. Obtenemos el objeto de tipo SpeechRecognitionResult

2. Obtener otros parámetros

Step 22º Paso

1º Paso

3º Paso3º Paso

Page 28: Integrando nuestra Aplicación Windows Phone con Cortana

Demo 4Gestionando la activación desde el comando de voz

Page 29: Integrando nuestra Aplicación Windows Phone con Cortana

quiere?

Recomendaciones en el diseñoQue es lo que el usuario

Usa frases simples en los comandos del archivo VCD (Elementos <ListenFor>).

❷ Gestiona una Comunicación compleja procesando texto en la propia aplicación.

Page 30: Integrando nuestra Aplicación Windows Phone con Cortana

Recomendaciones en el diseñoFeedback

Manten al usuario SIEMPRE informado sobre lo que ocurre.❶

❷ Adapta siempre la respuesta segun la petición del usuario.Analiza, analiza: Considera en todo momento el coste / beneficio de cada palabra utilizada.

❹ Variedad/Repetición: ¿El usuario se cansa de siempre lo mismo?

Page 31: Integrando nuestra Aplicación Windows Phone con Cortana

¿Ha sido la App activada por un comando de voz?

Si es asi… es posible que deseemos continuar la conversación con el usuario dentro de la App…

Continuar la conversación

Page 32: Integrando nuestra Aplicación Windows Phone con Cortana

Reconocimiento de voz// Windows Phone Store App

// Recognitionprivate async Task<SpeechRecognitionResult> RecognizeSpeech(){ SpeechRecognizer recognizer = new SpeechRecognizer();

// One of three Constraint types available SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebSearch, "MSDN"); recognizer.Constraints.Add(topicConstraint);

await recognizer.CompileConstraintsAsync(); // Required

// Put up UI and recognize user's utterance SpeechRecognitionResult result = await recognizer.RecognizeWithUIAsync();

return result;}// Calling code uses result.RecognitionResult.Text or// result.RecognitionResult.SemanticInterpretation

Page 33: Integrando nuestra Aplicación Windows Phone con Cortana

Reconocimiento de voz// Windows Phone Store App

// Recognitionprivate async Task<SpeechRecognitionResult> RecognizeSpeech(){ SpeechRecognizer recognizer = new SpeechRecognizer();

// One of three Constraint types available SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebSearch, "MSDN"); recognizer.Constraints.Add(topicConstraint);

await recognizer.CompileConstraintsAsync(); // Required

// Put up UI and recognize user's utterance SpeechRecognitionResult result = await recognizer.RecognizeWithUIAsync();

return result;}// Calling code uses result.RecognitionResult.Text or// result.RecognitionResult.SemanticInterpretation

SpeechRecognizer recognizer = new SpeechRecognizer();

// One of three Constraint types availableSpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint( SpeechRecognitionScenario.WebSearch, "MSDN"); recognizer.Constraints.Add(topicConstraint);

await recognizer.CompileConstraintsAsync(); // Requerido

“constraints”Three steps to adding a constraint:

1. Crear el constraint

2. Añadirlo a la colección

3. Utilizar el método CompileConstraintsAsync

Page 34: Integrando nuestra Aplicación Windows Phone con Cortana

Reconocimiento de voz// Windows Phone Store App

// Recognitionprivate async Task<SpeechRecognitionResult> RecognizeSpeech(){ SpeechRecognizer recognizer = new SpeechRecognizer();

// One of three Constraint types available SpeechRecognitionTopicConstraint topicConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebSearch, "MSDN"); recognizer.Constraints.Add(topicConstraint);

await recognizer.CompileConstraintsAsync(); // Required

// Put up UI and recognize user's utterance SpeechRecognitionResult result = await recognizer.RecognizeWithUIAsync();

return result;}// Calling code uses result.RecognitionResult.Text or// result.RecognitionResult.SemanticInterpretation

// Put up UI and recognize user's utterance SpeechRecognitionResult result = await recognizer.RecognizeWithUIAsync();

return result;}// Calling code uses result.RecognitionResult.Text or// result.RecognitionResult.SemanticInterpretation

Utilizamos el método RecognizeWithUIAsync para usar la UI del sistema, RecognizeAsync para gestionarlo nosotors mismos

Page 35: Integrando nuestra Aplicación Windows Phone con Cortana

3 pasos para extender nuestra aplicación e integrarla con CortanaCrear la definición de comandos de voz

Instalar el archive xml VCD en el arranque de la aplicación

Gestionar los commandos de voz en la activación de la aplicación

Escenarios: Comunicar, encontrar, recordarComandos cortos y sencillos

Encontrar contenido en grandes listados, contenido, etc.

Ayuda al usuario a realizar tareas complejas o a recordar completarlas más tarde

Conclusiones

Page 36: Integrando nuestra Aplicación Windows Phone con Cortana

Preguntas y respuestas.

¿Dudas?

P&R

Page 37: Integrando nuestra Aplicación Windows Phone con Cortana

Integrando nuestra Aplicación Windows Phone con Cortana

Gracias por vuestro tiempo!