Windows 10 - programming Cortana Windows 10 - programming Cortana windows windows

Windows 10 - programming Cortana


The VCD definition file you've listed above doesn't have either a PhraseTopic or PhraseList to define the parts you've got in curly braces:

 <ListenFor> {farenheit} farenheit to degrees </ListenFor>

I'm guessing you probably wanted a PhraseTopic because that allows for an unconstrained dictation suitable for a wide range of numbers, something like this:

<PhraseTopic Label="farenheit" Scenario="Dictation">   <Subject>Temperature</Subject></PhraseTopic>

See the spec for VCD's here on msdn, you might want to play with tweaking the Scenario value. This does mean you'll need to handle the text you get as the farenheit term yourself, of course, but typically dictated text for numbers comes through in textual '1234' form (but not in 100% of cases).


check the properties of your VCD file, values shoud be: Buil Action = Content, Copy to Output Directory = Copy always. Anyway, I hope that you registered the vcd file:

VoiceCommandService.InstallCommandSetsFromFileAsync(new Uri("ms-appx:///VCD.xml"));

Check this MVA video about Cortana: https://www.microsoftvirtualacademy.com/en-US/training-courses/universal-windows-app-development-with-cortana-and-the-speech-sdk-8487


Well... Seems that you have understood all the steps but still something is missing...

Here's an example that I have made regarding Cortana's foreground functionality:

Here's the VCD...

    <?xml version="1.0" encoding="utf-8" ?>    <VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">      <CommandSet xml:lang="en-us" Name="HomeControlCommandSet_en-us">        <CommandPrefix>HomeControl</CommandPrefix>        <Example>Control alarm, temperature, light and others</Example>        <Command Name="Activate_Alarm">          <Example>Activate alarm</Example>          <ListenFor>[Would] [you] [please] activate [the] alarm [please]</ListenFor>          <ListenFor RequireAppName="BeforeOrAfterPhrase">Activate alarm</ListenFor>          <ListenFor RequireAppName="ExplicitlySpecified">Activate {builtin:AppName} alarm</ListenFor>          <Feedback>Activating alarm</Feedback>          <Navigate />        </Command>

After create this definitions, you need to registry it at App Startup:

    protected async override void OnLaunched(LaunchActivatedEventArgs e)    {        ...        // Install the VCD        try        {            StorageFile vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync(@"HomeControlCommands.xml");            await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile);        }        catch (Exception ex)        {            System.Diagnostics.Debug.WriteLine("There was an error registering the Voice Command Definitions", ex);        }    }

An then override App.OnActivated method to handle when the events are triggered:

    protected override void OnActivated(IActivatedEventArgs e)    {        // Handle when app is launched by Cortana        if (e.Kind == ActivationKind.VoiceCommand)        {            VoiceCommandActivatedEventArgs commandArgs = e as VoiceCommandActivatedEventArgs;            SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;            string voiceCommandName = speechRecognitionResult.RulePath[0];            string textSpoken = speechRecognitionResult.Text;            IReadOnlyList<string> recognizedVoiceCommandPhrases;            System.Diagnostics.Debug.WriteLine("voiceCommandName: " + voiceCommandName);            System.Diagnostics.Debug.WriteLine("textSpoken: " + textSpoken);            switch (voiceCommandName)            {                case "Activate_Alarm":                    System.Diagnostics.Debug.WriteLine("Activate_Alarm command");                    break;

To see the complete tutorial, please visit this link and a working project is here. Also, if you interested in respond to the user through Cortana window, check this post regarding Cortana in background