Cortana集成失败
本文关键字:失败 集成 Cortana | 更新日期: 2023-09-27 18:26:32
我正在制作一个基于Windows 8.1语音的应用程序。我的问题是,当我给Cortana输入时,它会启动我的应用程序,应用程序会在屏幕上关闭,但当我在后台运行应用程序(最小化应用程序)或应用程序正在运行时,Cortana的输入效果非常好。
我哪里错了?这是我的app.xaml.cs代码,在OnActivatedMethod:中
if (args.Kind == ActivationKind.VoiceCommand)
{
VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;
string voiceCommandName = vcArgs.Result.RulePath.First(); // What command launched the app?
switch (voiceCommandName) // Run the action specific to the command
{
case "comand1": // User said comand1
rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
break;
case "comand2": // User said comand2
rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
break;
case "comand3": // User said comand3
rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
break;
case "comand4":
rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
break;
}
以及在语音处理页面的OnNavigated方法中:
SpeechRecognitionResult vcArgs = e.Parameter as SpeechRecognitionResult;
RcvdCommand = vcArgs.Text.ToUpper();
// Check for null!
string commandMode = vcArgs.SemanticInterpretation.Properties["commandMode"][0];
if (commandMode == "voice") // Did the user speak or type the command?
{
RequestHanding();
MyTextblock.Text = vcArgs.Text;
// SpeakText(audioPlayer, String.Format(" app heard you say {0}", RcvdCommand ));
// HandleNlpCommand(vcArgs);
}
else if (commandMode == "text")
{
// messageTextBox.Text = string.Format("Working on your request '"{0}'"", RcvdCommand);
// HandleNlpCommand(vcArgs);
}
当应用程序未运行并且通过语音命令激活时,不会调用OnLaunched()方法。因此,您需要调用确保在OnActivated()方法中也创建根框架的代码:
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
// ... restore app state, etc.
Window.Current.Content = rootFrame;
}