Cortana Windows 10 UWP 集成 - 在 VCD 中使用 {*}

Cortana Windows 10 UWP Integration - Using {*} in VCD

specification for vcd files中说{*}是用来匹配任何东西的。但是对于他的示例命令:

<Command Name="addFoodLog">
      <Example> I had a burger for lunch </Example>
      <!--Recording a drink-->
      <ListenFor RequireAppName="BeforeOrAfterPhrase"> [I] drank [a] {*} with [my] {mealtime} </ListenFor>
      <!--Recording a meal-->
      <ListenFor RequireAppName="BeforeOrAfterPhrase"> [I] ate [a] {*} for [my] {mealtime} </ListenFor>
      <ListenFor RequireAppName="BeforeOrAfterPhrase"> [I'm] having {*} for [my] {mealtime} </ListenFor>
      <ListenFor RequireAppName="BeforeOrAfterPhrase"> [I] [just] had [a] {*} for {mealtime} </ListenFor>
      <Feedback> Recording your {mealtime}</Feedback>
      <Navigate />
</Command>

打印此输入的结果将是 I drank a ... with my dinner

有什么方法可以从文本中提取出实际所说的内容吗?或者这是一个错误?

如果您使用短语主题,那么您的问题就会得到解决,因为它会吸收更多的词汇。

举个例子:

<PhraseTopic Label="food">
  <Subject>Food</Subject>
  <Subject>Drink</Subject>
  <Subject>Meal</Subject>
  <Subject>Food</Subject>
</PhraseTopic>

查看 Voice Command Definition elements and attributes 了解更多信息

下面是您如何获取搜索词,而不是从值列表中获取。这是针对 HTML/JS,而不是 XAML,但应该会给您一个好主意。

XML

<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
    <CommandSet xml:lang="en-us" Name="FNOW_en-us">
        <AppName> YourAppName </AppName>
        <Example> Search books </Example>

        <Command Name="SearchFor">
            <Example> Search for Harry Potter </Example>
            <ListenFor RequireAppName="BeforeOrAfterPhrase"> find book {SearchTerm} </ListenFor>
            <Feedback> Searching books </Feedback>
            <Navigate />
        </Command>

        <PhraseTopic Label="SearchTerm" Scenario="Search"/>
    </CommandSet>
</VoiceCommands>

JavaScript

function handleVoiceCommand(args) {
    var command,
        commandResult,
        commandName = '',
        commandProperties = {};

    if (args.detail && args.detail.detail) {
        command = args.detail.detail[0];

        if (command) {
            commandResult = command.result;

            if (commandResult) {
                if (commandResult.rulePath) {
                    commandName = commandResult.rulePath[0];
                }
                if (commandResult.semanticInterpretation) {
                    commandProperties = commandResult.semanticInterpretation.properties;
                }

                // Act on the different commands.
                // Command Names are defined within VoiceCommands.xml.
                switch(commandName) {
                    case 'SearchFor':
                        console.log('Cortana Command: SearchFor');
                        console.log('Search Term: ' + commandProperties.SearchTerm[0]);
                        break;
                }
            }
        }
    }
}

WinJS.Application.addEventListener('activated', function (args) {
    var appLaunchVoiceCommand;

    appLaunchVoiceCommand = Windows.ApplicationModel.Activation.ActivationKind.voiceCommand || 16;
    if (args.detail.kind === appLaunchVoiceCommand) {
        return handleVoiceCommand(args);
    }
});

WinJS.Application.start();