コード例 #1
0
 private async void SaveXML1()
 {
     List <string> Places = new List <string> {
         "Auckland", "Wellington", "Christchurch"
     };
     var VCD = new VoiceCommandDefinition()
     {
         CommandSets =
         {
             new CommandSet("en")
             {
                 Example  = "Book trips to Destinations",
                 AppName  = "TravelPlan",
                 Name     = "TravelPlanCommands(English)",
                 Commands =
                 {
                     new ForegroundActivatedVoiceCommand("Command")
                     {
                         Example          = "Book a Trip to Wellington",
                         Feedback         = "Booking Trip",
                         ListenStatements =
                         {
                             new ListenStatement("Book [a] Trip [to] {Places}",                                            RequireAppName.BeforeOrAfterPhrase),
                             new ListenStatement("[I] [would] [like] [to] Book [a] [my] [Holiday] [Trip] to {searchTerm}",
                                                 RequireAppName.BeforeOrAfterPhrase)
                         },
                         AppTarget = "BOOKTRIP"
                     }
                 },
                 PhraseLists =
                 {
                     new PhraseList("Places", Places)
                 },
                 PhraseTopics =
                 {
                     new PhraseTopic("searchTerm", PhraseTopicScenario.Search)
                     {
                         Subjects =
                         {
                             PhraseTopicSubject.CityORState
                         }
                     }
                 }
             }
         }
     };
     await VCD.CreateAndInstall();
 }
コード例 #2
0
        private static async Task RegisterVoiceCommands(string file_path)
        {
            //launch cortana integration (foreground)
            var vcd_path = file_path;
            var vcd_uri  = new Uri(vcd_path);
            var vcd_file = await StorageFile.GetFileFromApplicationUriAsync(vcd_uri);

            await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcd_file);

            //modifying phrase list programmatically (for more dynamic interactions)
            VoiceCommandDefinition command_set = VoiceCommandDefinitionManager.InstalledCommandDefinitions["en-us-CommandSet"];

            //for location
            await command_set.SetPhraseListAsync("location", new string[]
                                                 { "London",
                                                   "Dallas",
                                                   "Maine",
                                                   "Phoenix",
                                                   "Miami",
                                                   "Boston",
                                                   "Chicago",
                                                   "New York",
                                                   "my regular spot", });
        }
コード例 #3
0
        private async void SaveXML()
        {
            Setting appNameSetting = App.GetStringSettingByName("appname");
            string  appName        = "Command";

            if (appNameSetting != null && appNameSetting.Value.Trim().Length > 0)
            {
                appName = appNameSetting.Value.Trim();
            }
            var xmlNode = new XElement("commands");
            var VCD     = new VoiceCommandDefinition()
            {
            };
            var CS = new CommandSet("de-de")
            {
                Example      = "Command do something",
                AppName      = appName,//prefix TODO StringSetting variable
                Name         = "CommandCommandSet_de-de",
                PhraseTopics =
                {
                    new PhraseTopic("searchTerm", PhraseTopicScenario.ShortMessage)
                    {
                    }
                }/*,
                  * PhraseLists =
                  * {
                  * new PhraseList("result", new List<string>{ })
                  * }*/
            };

            foreach (CustomCommand customcommand in this.ViewModel.Commands)
            {
                // Add VoiceCommand
                var command = new BackgroundActivatedVoiceCommand(customcommand.Name)
                {
                    Example          = customcommand.Example,
                    Feedback         = customcommand.Feedback,
                    ListenStatements =
                    {
                        new ListenStatement(customcommand.ListenFor, RequireAppName.BeforePhrase)
                    },
                    BackgroundTarget = "VoiceCommandService"
                };
                CS.Commands.Add(command);
                XElement xmlCommand =
                    new XElement("command",
                                 new XAttribute("name", customcommand.Name),
                                 new XAttribute("example", customcommand.Example),
                                 new XAttribute("listenfor", customcommand.ListenFor),
                                 new XAttribute("feedback", customcommand.Feedback),
                                 new XAttribute("batchcommand", customcommand.BatchCommand)
                                 );
                xmlNode.Add(xmlCommand);
            }
            VCD.CommandSets.Add(CS);
            try
            {
                // Save and install VCD file
                await VCD.CreateAndInstall();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(CS.Commands);
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            // Save FileCustomCommands.xml
            xmlNode.Save(fileCommandsXMLPath);

            ContentDialog savedDialog = new ContentDialog
            {
                IsSecondaryButtonEnabled = false,
                Title             = "Saved commands!",
                Content           = "",
                PrimaryButtonText = "Ok, cool!"
            };

            await savedDialog.ShowAsync();
        }