[英]dynamically populate VoiceCommand PhraseList, Error VoiceCommandSet not found
我正在寻找一种动态填充VCD文件的方法。 我有Windows文档中的代码片段,内容如下:
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会显示一个错误,指出“ Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinition”中不包含VoiceCommandSet。 我的问题是:
我在错误的地方吗? 您是否知道任何示例项目,说明如何正确执行此操作? (我调查了Adventure Works,但是没有在那找到这些行)还是我缺少一些我不知道的参考?
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());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.