【问题标题】:dynamically populate VoiceCommand PhraseList, Error VoiceCommandSet not found动态填充 VoiceCommand PhraseList,找不到错误 VoiceCommandSet
【发布时间】:2018-05-17 22:36:29
【问题描述】:

我正在寻找一种方法来动态填充我的 VCD 文件。我有一个来自 Windows 文档的代码 sn-p,内容如下:

Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinition.VoiceCommandSet commandSetEnUs;

if (Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinitionManager.
      InstalledCommandSets.TryGetValue(
        "AdventureWorksCommandSet_en-us", out commandSetEnUs))
{
  await commandSetEnUs.SetPhraseListAsync(
    "destination", new string[] {“London”, “Dallas”, “New York”, “Phoenix”});
}

但是,当我将它放入我的 App.OnActivated() 版本时,Visual Studio 显示一个错误,指出 VoiceCommandSet 不包含在“Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinition”中。我的问题是:

我这样做是不是在错误的地方?你知道任何示例项目,显示如何正确地做到这一点? (我查看了 Adventure Works,但没有在那边找到这些行)还是我遗漏了一些我不知道的参考资料?

【问题讨论】:

  • 同时我发现 AdventureWorks 在 TripViewModel.UpdateDestinationPhraseList 中这样做

标签: cortana phrases vcd


【解决方案1】:
public async Task UpdateDestinationPhraseList()
        {
            try
            {
                // Update the destination phrase list, so that Cortana voice commands can use destinations added by users.
                // When saving a trip, the UI navigates automatically back to this page, so the phrase list will be
                // updated automatically.
                VoiceCommandDefinition commandDefinitions;

                string countryCode = CultureInfo.CurrentCulture.Name.ToLower();
                if(countryCode.Length == 0)
                {
                    countryCode = "en-us";
                }

                if (VoiceCommandDefinitionManager.InstalledCommandDefinitions.TryGetValue("AdventureWorksCommandSet_" + countryCode, out commandDefinitions))
                {
                    List<string> destinations = new List<string>();
                    foreach (Model.Trip t in store.Trips)
                    {
                        destinations.Add(t.Destination);
                    }

                    await commandDefinitions.SetPhraseListAsync("destination", destinations);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Updating Phrase list for VCDs: " + ex.ToString());
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 2011-01-23
    相关资源
    最近更新 更多