hands free with cortana

19
Handsfree with Cortana

Upload: fiyaz-hasan

Post on 22-Jan-2018

57 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Hands free with cortana

Handsfree with Cortana

Page 2: Hands free with cortana

“I’m Fiyaz Hasan

#Versatile #Tech #Developer

I’m a .NET and JavaScript enthusiast. I like to work with

different technologies on different platforms. I love the

logic and structure of coding and always strives to write

more elegant and efficient code. I’m passionate about

design patterns and applying Software Engineering best

practices.

www.fiyazhasan.me

Page 3: Hands free with cortana

Hey Cortana, Who am I?

You are Fizz

Page 4: Hands free with cortana

Hey Cortana, Who are you?

I am Cortana

Page 5: Hands free with cortana

Integrating with Cortana in 3 simple steps

Create Voice Command

Definition (s)Register VCD on

App StartupHandle Voice

Command Activation

Page 6: Hands free with cortana

CREATING VOICE COMMAND DEFINATION(S)

Page 7: Hands free with cortana

Step 1

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

<CommandSet xml:lang="en-us" Name="MySimpleTodoCommandSet_en-us">

<CommandPrefix> My Simple To do </CommandPrefix>

<Example> pending tasks </Example>

<Command Name="todoBackgroundCommandList">

<Example> pending tasks </Example>

<ListenFor> {command} task[s] </ListenFor>

<Feedback> Executing specific command </Feedback>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

</Command>

<PhraseTopic Label="command" Scenario="Search">

<Subject> pending </Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

Create Voice Command Definition(s)

Note: the VCD is identical for JavaScript and C# apps

Page 8: Hands free with cortana

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

<CommandSet xml:lang="en-us" Name="MySimpleTodoCommandSet_en-us">

<CommandPrefix> My Simple To do </CommandPrefix>

<Example> pending tasks </Example>

<Command Name="todoBackgroundCommandList">

<Example> pending tasks </Example>

<ListenFor> {command} task[s] </ListenFor>

<Feedback> Executing specific command </Feedback>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

</Command>

<PhraseTopic Label="command" Scenario="Search">

<Subject> pending </Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<CommandPrefix> My Simple To do </CommandPrefix>

Step 1

Page 9: Hands free with cortana

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

<CommandSet xml:lang="en-us" Name="MySimpleTodoCommandSet_en-us">

<CommandPrefix> My Simple To do </CommandPrefix>

<Example> pending tasks </Example>

<Command Name="todoBackgroundCommandList">

<Example> pending tasks </Example>

<ListenFor> {command} task[s] </ListenFor>

<Feedback> Executing specific command </Feedback>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

</Command>

<PhraseTopic Label="command" Scenario="Search">

<Subject> pending </Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<Example> pending tasks </Example>

Step 1

Page 10: Hands free with cortana

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

<CommandSet xml:lang="en-us" Name="MySimpleTodoCommandSet_en-us">

<CommandPrefix> My Simple To do </CommandPrefix>

<Example> pending tasks </Example>

<Command Name="todoBackgroundCommandList">

<Example> pending tasks </Example>

<ListenFor> {command} task[s] </ListenFor>

<Feedback> Executing specific command </Feedback>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

</Command>

<PhraseTopic Label="command" Scenario="Search">

<Subject> pending </Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<Command Name="todoBackgroundCommandList"><Example> pending tasks </Example><ListenFor> {command} task[s] </ListenFor><Feedback> showing {command} tasks </Feedback><VoiceCommandService

Target="SimpleTodoVoiceCommandService"/></Command>

Step 1

Page 11: Hands free with cortana

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

<CommandSet xml:lang="en-us" Name="MySimpleTodoCommandSet_en-us">

<CommandPrefix> My Simple To do </CommandPrefix>

<Example> pending tasks </Example>

<Command Name="todoBackgroundCommandList">

<Example> pending tasks </Example>

<ListenFor> {command} task[s] </ListenFor>

<Feedback> Executing specific command </Feedback>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

</Command>

<PhraseTopic Label="command" Scenario="Search">

<Subject> pending </Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<Example> pending tasks </Example>

Step 1

Page 12: Hands free with cortana

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

<CommandSet xml:lang="en-us" Name="MySimpleTodoCommandSet_en-us">

<CommandPrefix> My Simple To do </CommandPrefix>

<Example> pending tasks </Example>

<Command Name="todoBackgroundCommandList">

<Example> pending tasks </Example>

<ListenFor> {command} task[s] </ListenFor>

<Feedback> Executing specific command </Feedback>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

</Command>

<PhraseTopic Label="command" Scenario="Search">

<Subject> pending </Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<ListenFor> {command} task[s] </ListenFor>

Step 1

Page 13: Hands free with cortana

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

<CommandSet xml:lang="en-us" Name="MySimpleTodoCommandSet_en-us">

<CommandPrefix> My Simple To do </CommandPrefix>

<Example> pending tasks </Example>

<Command Name="todoBackgroundCommandList">

<Example> pending tasks </Example>

<ListenFor> {command} task[s] </ListenFor>

<Feedback> Executing specific command </Feedback>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

</Command>

<PhraseTopic Label="command" Scenario="Search">

<Subject> pending </Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<Feedback> Executing specific command </Feedback>

Step 1

Page 14: Hands free with cortana

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

<CommandSet xml:lang="en-us" Name="MySimpleTodoCommandSet_en-us">

<CommandPrefix> My Simple To do </CommandPrefix>

<Example> pending tasks </Example>

<Command Name="todoBackgroundCommandList">

<Example> pending tasks </Example>

<ListenFor> {command} task[s] </ListenFor>

<Feedback> Executing specific command </Feedback>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

</Command>

<PhraseTopic Label="command" Scenario="Search">

<Subject> pending </Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

Step 1

Page 15: Hands free with cortana

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

<CommandSet xml:lang="en-us" Name="MySimpleTodoCommandSet_en-us">

<CommandPrefix> My Simple To do </CommandPrefix>

<Example> pending tasks </Example>

<Command Name="todoBackgroundCommandList">

<Example> pending tasks </Example>

<ListenFor> {command} task[s] </ListenFor>

<Feedback> Executing specific command </Feedback>

<VoiceCommandService Target="SimpleTodoVoiceCommandService"/>

</Command>

<PhraseTopic Label="command" Scenario="Search">

<Subject> pending </Subject>

</PhraseTopic>

</CommandSet>

</VoiceCommands>

<PhraseTopic Label="command" Scenario="Search"><Subject> pending </Subject>

</PhraseTopic>

Step 1

Page 16: Hands free with cortana

Register VCD XML file on App Startup

Page 17: Hands free with cortana

private async Task RegisterVoiceCommands()

{

var storageFile =

await StorageFile.GetFileFromApplicationUriAsync(

new Uri("ms-appx:///MySimpleTodoCommands.xml"));

await

VoiceCommandDefinitionManager

.InstallCommandDefinitionsFromStorageFileAsync(storageFile);

}Step 2

Register VCD XML file on App Startup

Step 1

Page 18: Hands free with cortana

Handle Voice Command Activation

Page 19: Hands free with cortana

Step 3

Step 1

Step 2

Handle Voice Command Activationvar triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails;

if (triggerDetails?.Name == "SimpleTodoVoiceCommandService")

{

_deferral = taskInstance.GetDeferral();

var cancelledTokenSource = new CancellationTokenSource();

_voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails);

var voiceCommand = await _voiceServiceConnection.GetVoiceCommandAsync();

switch (voiceCommand.CommandName)

{

case "todoBackgroundCommandList":

var command = voiceCommand.Properties["command"][0];

if (command == "pending")

await ();

break;

default:

();

break;

}

}