【问题标题】:Cortana integration faliureCortana 集成失败
【发布时间】: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


    【解决方案1】:

    当应用程序未运行并通过语音命令激活时,不会调用 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;
      }
    

    【讨论】:

    • 您好,谢谢您的回答。有用。我只有一个查询,我的应用程序工作正常,现在它把我带到它处理 cortana 请求的页面,唯一的问题是它没有通过语音响应用户。它应该通过回复与用户对话。相反,它什么也不做。同样在另一种情况下,应用程序必须回话然后显示 phonecallUI,而不是直接显示 PhoneCallUI 而没有回话。我哪里错了?
    • 您如何尝试让应用程序与用户对话?我使用这个代码: SpeechSynthesizer synthesizer = new SpeechSynthesizer(); var 流 = 等待合成器。SynthesizeTextToStreamAsync(text); media.SetSource(流, "");其中 media 是页面上的 MediaElement 控件
    • 是的,是的,我使用的是相同的代码。此外,当我使用在后台运行的应用程序时,回话的整个过程工作得非常好,就在我使用语音命令启动应用程序时,页面被导航到 SpeechHandling 页面(感谢你)但应用程序没有与用户对话。
    • 附注。如果在 Cortana 中键入命令,请确保您的应用程序仅在用户与其交谈时回复,应用程序应仅使用 UI 回复。
    猜你喜欢
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    相关资源
    最近更新 更多