Cortana is not working for 'what is engineering' but working for 'what is gravity' even though VCD file is loaded without exceptions. The commands are registered under 'what can i say' page.
Changes are done above the sample code given at https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CortanaVoiceCommand
AdventureWorksCommand.xml
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-in" Name="AdventureWorksCommandSet_en-in">
<AppName> ask assistant</AppName>
<Example> what is gravity </Example>
<Command Name="q1">
<Example>what is engineering</Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase">what is engineering</ListenFor>
<Feedback> Let me check that for you</Feedback>
<VoiceCommandService Target="AdventureWorksVoiceCommandService"/>
</Command>
<Command Name="q2">
<Example>what is gravity</Example>
<ListenFor RequireAppName="BeforeOrAfterPhrase">what is gravity</ListenFor>
<Feedback> Let me check that for you</Feedback>
<VoiceCommandService Target="AdventureWorksVoiceCommandService"/>
</Command>
In AdventureWorksVoiceCommandService.cs, default part of switch case connects to a third party service and gets response,
try
{
voiceServiceConnection =
VoiceCommandServiceConnection.FromAppServiceTriggerDetails(
triggerDetails);
voiceServiceConnection.VoiceCommandCompleted += OnVoiceCommandCompleted;
// GetVoiceCommandAsync establishes initial connection to Cortana, and must be called prior to any
// messages sent to Cortana. Attempting to use ReportSuccessAsync, ReportProgressAsync, etc
// prior to calling this will produce undefined behavior.
VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync();
// Depending on the operation (defined in AdventureWorks:AdventureWorksCommands.xml)
// perform the appropriate command.
switch (voiceCommand.CommandName)
{
case "whenIsTripToDestination":
var destination = voiceCommand.Properties["destination"][0];
await SendCompletionMessageForDestination(destination);
break;
case "cancelTripToDestination":
var cancelDestination = voiceCommand.Properties["destination"][0];
await SendCompletionMessageForCancellation(cancelDestination);
break;
//case "myBalance":
// string result = "";
// //string speech = "My Balance is 100 dollars great! My Balance is 100 dollars great!My Balance is 100 dollars great!";
// string speech = voiceCommand.SpeechRecognitionResult.Text;
// ApiAiService service = new ApiAiService();
// result = await service.getResult(speech);
// await SendMessageToPlay(result);
// //ApiAiService service = new ApiAiService();
// //s.PlayMedia("You are doing great, your balance is 100 dollars");
// break;
default:
// As with app activation VCDs, we need to handle the possibility that
// an app update may remove a voice command that is still registered.
// This can happen if the user hasn't run an app since an update.
//LaunchAppInForeground();
string result = "";
//string speech = "My Balance is 100 dollars great! My Balance is 100 dollars great!My Balance is 100 dollars great!";
string speech = voiceCommand.SpeechRecognitionResult.Text;
ApiAiService service = new ApiAiService();
result = await service.getResult(speech);
await SendMessageToPlay(result);
break;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Handling Voice Command failed " + ex.ToString());
}