I'm working on getting Cortana interacting with a background app service. Cortana is working with one voice command set but when I try any of the voice commands from a different command set, it just opens the search in Bing.
Any suggestions on what might be causing it or changes to the commands to make it work better with Cortana?
The command set that doesn't work:
<Command Name="SetTemperatureDefault">
<Example> change the temperature to 72 degrees </Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> set [the] temperature to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> change [the] temperature to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> increase [the] temperature to {Temperature} </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> decrease [the] temperature to {Temperature} </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> set to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> change to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> increase to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> decrease to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> set temp to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> change temp to {Temperature} degrees </ListenFor>
<Feedback> Changing temperature... </Feedback>
<VoiceCommandService Target="CozyVoiceCommandService" />
</Command>
First of all, guarantee that your VCD has been installed correctly during app initialization. Make sure that it's not giving any exception.
protected async override void OnLaunched(LaunchActivatedEventArgs e)
{
...
// Install the VCD
try
{
StorageFile vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync(@"HomeControlCommands.xml");
await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("There was an error registering the Voice Command Definitions", ex);
}
}
Then, as you are using {Temperature} for commands, you need to use a PhraseTopic after you list all the Command.
...
<Command Name="SetTemperatureDefault">
<Example> change the temperature to 72 degrees </Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> set [the] temperature to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> change [the] temperature to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> increase [the] temperature to {Temperature} </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> decrease [the] temperature to {Temperature} </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> set to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> change to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> increase to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> decrease to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> set temp to {Temperature} degrees </ListenFor>
<ListenFor RequireAppName="BeforeOrAfterPhrase"> change temp to {Temperature} degrees </ListenFor>
<Feedback> Changing temperature... </Feedback>
<VoiceCommandService Target="CozyVoiceCommandService" />
</Command>
<PhraseTopic Label="Temperature" />
</CommandSet>
</VoiceCommands>
I have tested it here and it work like a charm.
Here's a complete tutorial for Cortana in foreground that can be helpful in some other situation you may need.