首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cortana集成失败

Cortana集成失败
EN

Stack Overflow用户
提问于 2015-12-11 05:00:18
回答 1查看 150关注 0票数 0

我正在制作一个基于Windows8.1演讲的应用程序。我的问题是,当我给Cortana提供它启动我的应用程序的输入时,应用程序会在屏幕上关闭,但是当我在后台运行我的应用程序(最小化应用程序)时,或者当应用程序运行时,Cortana输入法工作得很完美。

我哪里出问题了?下面是我的app.xaml.cs代码,在OnActivatedMethod中:

代码语言:javascript
复制
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方法中:

代码语言:javascript
复制
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);
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-11 12:42:45

当应用程序没有运行,并且由语音命令激活时,不会调用OnLaunched()方法。因此,您需要调用确保在OnActivated()方法中创建根框架的代码:

代码语言:javascript
复制
  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;
  }
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34216435

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档