2016-02-11 49 views
0

我在尝试更新我的UWP(Windows 10)应用程序的短语列表,但不是我没有理由为此而发生'灾难性故障'。SetPhraseListAsync - 灾难性故障

我注册柯塔娜像这样在App.xaml.cs

StorageFile vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync(@"VoiceCommandDefinition.xml"); 
await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile); 
Debug.WriteLine("Cortana loaded"); 

然后我打开我的数据(这是一个鸟巢恒温器客户端,所以我加载恒温器和结构)。之后,我尝试更新短语列表。

string thermostatsStrings = ""; 
string structureStrings = ""; 
VoiceCommandDefinition commandSetEnUs; 
if (VoiceCommandDefinitionManager.InstalledCommandDefinitions.TryGetValue("Nest_en-us", out commandSetEnUs)) 
{ 
    try 
    { 
     List<Nest.Thermostat> thermostats = GetAllThermostats(); 
     if (thermostats != null) 
     { 
      thermostatsStrings = String.Join(", ", thermostats); 
      List<String> names = thermostats.Select(thermostat => thermostat.name).ToList(); 
      await commandSetEnUs.SetPhraseListAsync("nest", names); 
     } 
    } 
    catch (Exception ex) 
    { 
     Crashes.Log("Helpers - UpdatePhraseListThermostat", true, ex.Message + 
      Environment.NewLine + "Thermostats: " + thermostatsStrings + 
      Environment.NewLine + "Structures: " + structureStrings); 
    } 
    try 
    { 
     List<Nest.Structure> structures = GetAllStructures(); 
     if (structures != null) 
     { 
      structureStrings = String.Join(", ", structures); 
      List<String> names = structures.Select(structure => structure.name).ToList(); 
      await commandSetEnUs.SetPhraseListAsync("place", names); 
     } 
    } 
    catch (Exception ex) 
    { 
     Crashes.Log("Helpers - UpdatePhraseListStructure", true, ex.Message + 
      Environment.NewLine + "Thermostats: " + thermostatsStrings + 
      Environment.NewLine + "Structures: " + structureStrings); 
    } 
} 

我的VCD文件看起来像这样

<?xml version="1.0" encoding="utf-8" ?> 
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2"> 
<CommandSet xml:lang="en-US" Name="Nest_en-us"> 
<AppName> Nest </AppName> 
<Example> Open Nest </Example> 

<Command Name="RequestTemp"> 
    <Example>Nest, what is the current temperature </Example> 
    <ListenFor> What is [the] {nest} temperature </ListenFor> 
    <ListenFor> What is [the] temperature in the {nest} </ListenFor> 
    <ListenFor> What is [the] [current] temperature </ListenFor> 
    <Feedback> Getting the temperature </Feedback> 
    <VoiceCommandService Target="NestCommandService"/> 
</Command> 

<Command Name="SetHome"> 
    <Example> Nest, I'm coming home </Example> 
    <ListenFor> Set {place} to home </ListenFor> 
    <ListenFor> I am on my way to {place} </ListenFor> 
    <ListenFor> I am coming home </ListenFor> 
    <ListenFor> I am home </ListenFor> 
    <ListenFor> set [status] to home </ListenFor> 
    <ListenFor> set [state] to home </ListenFor> 
    <ListenFor> set [mode] to home </ListenFor> 
    <ListenFor> I am back </ListenFor> 
    <ListenFor> I am on my way [home] </ListenFor> 


    <Feedback> Setting mode to home </Feedback> 
    <VoiceCommandService Target="NestCommandService"/> 
</Command> 


<PhraseList Label="nest"> 

</PhraseList> 

<PhraseList Label="place"> 

</PhraseList> 

</CommandSet> 
</VoiceCommands> 

我建在错误记录在我的应用程序(METROLOG),这是它的日志:

2|2016-02-03T15:39:14.0034437+00:00|TRACE|2|Crashes|Helpers - UpdatePhraseListThermostat 
Catastrophic failure 

Catastrophic failure 

Thermostats: Living Room 
Structures: 
3|2016-02-03T16:03:32.2687198+00:00|TRACE|2|Crashes|Helpers - UpdatePhraseListStructure 
Catastrophic failure 

Catastrophic failure 

Thermostats: Living Room 
Structures: Home 

回答

0

有一对夫妇的代码中的错误。首先,如果你想从应用程序包安装VCD那么代码看起来有点像这样:

Uri uriVoiceCommands = new Uri("ms-appx:///VoiceCommandDefinition1.xml", UriKind.Absolute); 
     StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uriVoiceCommands); 
     await VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(file); 

其次,虽然宣称它不建议短语列表不插入语句列表内的任何元素,以便开始你必须放置至少1个元素。 第三,灾难性错误可能是因为您有很多代码正在运行以确定VCD的更新,我宁愿确定要放入短语列表中的值以单独的方法,然后使用以下代码进行更新短语动态列表:

Windows.Media.SpeechRecognition.VoiceCommandSet commandSetEnUs; 

    if (Windows.Media.SpeechRecognition.VoiceCommandManager.InstalledCommandSets.TryGetValue("AdventureWorksCommandSet_en-us", out commandSetEnUs)) 
    { 
     await commandSetEnUs.SetPhraseListAsync(
      "destination", new string[] { Value1Det, value2Det }); //where Value2Det and Value1Det are the resulted outputs from thermostat 
    } 
相关问题