質問

I want to build an app for ordering products in a restaurant. The waiter would say the command "Product SomeProduct, Quantity SomeQuantity, Observation SomeObservation". I saw many samples using an local grammar file with pre defined commands. How can I construct one grammar file at runtime with the products name comming from a database?

役に立ちましたか?

解決

You can have a grammar defined in file, and then update the possible products though code. For example, you can hafe following file:

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0">
  <CommandSet xml:lang="en-US" Name="ProductCommandSet">
    <CommandPrefix>MyApp</CommandPrefix>
    <Example> Product some product </Example>

    <Command Name="Product">
      <Example> Product some product </Example>
      <ListenFor> Product {products} </ListenFor>
      <Feedback> Selected {products} </Feedback>
      <Navigate Target="/../View/ItemPage.xaml" />
    </Command>

    <PhraseList Label="products">

    </PhraseList>

  </CommandSet>
</VoiceCommands>

As you can see, ther is no list of possible products. Once you have loaded the list of product from the DB, you can update the list of commands though code. For example if you have the list of products on a variable of type List<string> named productList:

VoiceCommandSet commandSet = VoiceCommandService.InstalledCommandSets["ProductCommandSet"];
commandSet.UpdatePhraseListAsync("products", productList);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top