【问题标题】:Windows Phone 8.1 Voice Recognition + NavigationService problemsWindows Phone 8.1 语音识别+导航服务问题
【发布时间】:2014-12-21 00:24:32
【问题描述】:

我正在使用语音识别为 Windows Phone 8.1 开发应用程序。 此时,我想使用语音命令在应用程序中导航。该应用程序有一个按钮来激活语音识别。

此时我的问题在于 NavigationService.Navigate。 当我按下按钮时,应用程序会识别我的语音(如“设置”),但会在 NavigationService 中引发异常。

当我在我的设备 (Nokia lumia 735) 中运行应用程序时会发生这种情况。 当我使用模拟器(8.1 wvga 4inch 512mb)时,应用程序运行良好,NavigationService 运行良好!

这个应用程序是学校项目的一部分,所以如果有人可以帮助我,我将非常高兴。

这是我此刻的代码:

按钮点击代码:

private async void btSpeak_Click(object sender, RoutedEventArgs e)
        {
            recoWithUI = new SpeechRecognizerUI();


            // Query for a recognizer that recognizes French as spoken in France.
            IEnumerable<SpeechRecognizerInformation> language = from recognizerInfo in InstalledSpeechRecognizers.All
                                                                         where recognizerInfo.Language == "en-US"
                                                                         select recognizerInfo;

            // Set the recognizer to the top entry in the query result.
            recoWithUI.Recognizer.SetRecognizer(language.ElementAt(0));

            // Build a string array, create a grammar from it, and add it to the speech recognizer's grammar set.
            string[] triviaCategories = { "activity tracker", "bmi caculator", "meal calculator", "nutrition chart", "settings" };
            recoWithUI.Recognizer.Grammars.AddGrammarFromList("categories", triviaCategories);

            // Display text to prompt the user's input.
            recoWithUI.Settings.ListenText = "Say an option: ";

            // Display an example of ideal expected input.
            recoWithUI.Settings.ExampleText = "Activity Tracker\n @BMI Calculator\n Meal Calculator\n Nutrition Chart\n Settings";

            // Deactivate the readout of recognized text to the user.
            recoWithUI.Settings.ReadoutEnabled = true;

            // Load the grammar set and start recognition.
            SpeechRecognitionUIResult result = await recoWithUI.RecognizeWithUIAsync();

            //  Handle the caputed voice
            if (!String.IsNullOrWhiteSpace(result.RecognitionResult.Text))
            {
                recoWithUI.Dispose();
                VoiceComandsRecognition(result.RecognitionResult.Text.ToString());
            }
            else
                return;

        }

以及处理已识别字符串的方法的代码:

public void VoiceComandsRecognition(string CapturedVoice)
        {
            try
            {
                switch (CapturedVoice)
                {
                    case "activity tracker":
                        NavigationService.Navigate(new Uri("/Pages/ActivityTracker.xaml", UriKind.Relative));
                        break;
                    case "bmi calculator":
                        NavigationService.Navigate(new Uri("/Pages/BMIcalculator.xaml", UriKind.Relative));
                        break;
                    case "meal calculator":
                        NavigationService.Navigate(new Uri("/Pages/MealCalculator.xaml", UriKind.Relative));
                        break;
                    case "nutrition chart":
                        NavigationService.Navigate(new Uri("/Pages/NutritionChart.xaml", UriKind.Relative));
                        break;
                    case "settings":
                         NavigationService.Navigate(new Uri("/WinHealth;component/Pages/SettingsPage.xaml", UriKind.RelativeOrAbsolute));
                         break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Erro ao reconhecer o comando. "+e.ToString());
            }
    }

这是个例外:

{System.Exception: 对 COM 组件的调用已返回错误 HRESULT E_FAIL。 在 MS.Internal.XcpImports.CheckHResult(UInt32 小时) 在 MS.Internal.XcpImports.SetValue(IManagedPeerBase obj,DependencyProperty 属性,String s) 在 MS.Internal.XcpImports.SetValue(IManagedPeerBase doh,DependencyProperty 属性,对象 obj) 在 System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp,对象值) 在 System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty 属性,EffectiveValueEntry& newEntry,对象 newValue) 在 System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty 属性,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,ValueOperation 操作) 在 System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp,对象值,布尔 allowReadOnlySet) 在 Microsoft.Phone.Controls.PhoneApplicationFrame.UpdateMargin(厚度区域,PageOrientation 方向) 在 Microsoft.Phone.Controls.PhoneApplicationFrame.OnVisibleRegionChange(对象发件人,VisibleRegionChangeEventArgs 参数) 在 Microsoft.Phone.Controls.PhoneApplicationFrame.System.Windows.Controls.IFrame.InternalOnVisibleRegionChange(对象发件人,VisibleRegionChangeEventArgs 参数) 在 System.EventHandler1.Invoke(Object sender, TEventArgs e) at System.Windows.Controls.Frame.FireEventHandler[T](EventHandler1 处理程序,对象发送者,T args) 在 Microsoft.Phone.Controls.PhoneApplicationPage.set_VisibleRegionInPhysicalPixels(RECT 值) 在 Microsoft.Phone.Controls.PhoneApplicationPage.UpdateCurrentVisualState() 在 Microsoft.Phone.Controls.PhoneApplicationFrame.InternalUpdateOrientationAndMarginForPage(PhoneApplicationPage visiblePage) 在 Microsoft.Phone.Controls.PhoneApplicationFrame.System.Windows.Controls.IFrame.InternalUpdateOrientationAndMarginForPage(IPhoneApplicationPage visiblePage) 在 System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject 内容,NavigationMode 模式) 在 System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult 结果)}

【问题讨论】:

  • 有什么异常?
  • @aloisdg 我已经更新了任务是例外。你能帮助我吗?谢谢
  • 你可以开始尝试this 吗?
  • 感谢您的网址。我一回到家就试试。谢谢
  • @aloisdg 它不能解决我的问题。我认为问题是由于异步按钮事件造成的。

标签: c#


【解决方案1】:

这是 Windows Phone 中已确认的错误。他们告诉我,微软将在 6-12 个月内修复它。

【讨论】:

  • 您是否有参考资料,例如 Connect 帖子的链接?
  • 我没有找到任何关于它的信息。你有什么可以证明的吗?
  • 我想使用捕获的语音命令浏览页面。我怎么能这样???这可能吗??
  • 您有任何关于您的问题的消息吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多