Cortana不适用于什么是工程'但是为了什么是引力而努力#39;即使VCD文件加载没有例外。这些命令是在“我能说什么”下注册的。页。
在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>
在AdventureWorksVoiceCommandService.cs中,switch case的默认部分连接到第三方服务并获得响应,
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());
}