我正在制作一个基于Windows8.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);
}发布于 2015-12-11 12:42:45
当应用程序没有运行,并且由语音命令激活时,不会调用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;
}https://stackoverflow.com/questions/34216435
复制相似问题