0

I'm trying to update the phrase lists of my UWP (Windows 10) app, but more than not I get a 'catastrophic failure' with no reason why.

I register Cortana like so in App.xaml.cs

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

Then I load my data (it's a Nest thermostat client, so I load the thermostats and structures). After that I try to update the phrase lists.

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);
    }
}

My VCD file looks like this

<?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>

I built in error logging in my app (MetroLog), this is what it logs:

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

1 Answer 1

0

There are a couple of mishaps in the code. Firstly if you're trying to install the VCD from the app package then the code looks somewhat like this:

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

Secondly, while declaring a phrase list it's not recommended to not insert any element inside the phrase list so initially you must put atleast 1 element. Thirdly, The Catastrophic error is maybe because you have a lot of code being run to determine the updation of the VCD, I would rather determine the values to be put in the phrase list in a separate method and then use the following code to update the phrase list dynamically:

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 
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.