【发布时间】:2016-01-02 04:39:16
【问题描述】:
我正在制作一个基于 Windows 8.1 语音的应用程序。我的问题是,当我向 Cortana 提供输入时,它会启动我的应用程序并在启动画面处关闭应用程序,但是当我在后台运行我的应用程序(最小化应用程序)或当应用程序运行时,Cortana 输入工作完美。
我哪里错了?这是我在 OnActivatedMethod 中的 app.xaml.cs 代码:
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);
}
【问题讨论】:
标签: c# windows-phone-8.1 speech-recognition speech-synthesis cortana