[英]Windows Phone 8.1 Voice Recognition + NavigationService problems
I'm developing an application for Windows Phone 8.1 using Speech recognition. 我正在开发使用语音识别的Windows Phone 8.1应用程序。 At this moment, I want navigate in the application using voice commands. 目前,我想使用语音命令在应用程序中导航。 The application has a button to active the voice recognition. 该应用程序具有激活语音识别的按钮。
My problem at this moment is in NavigationService.Navigate. 我目前的问题是在NavigationService.Navigate中。 When I press the button, the application recognize my voice speech (like "Settings") but throws an exception in the NavigationService. 当我按下按钮时,应用程序会识别我的语音(例如“设置”),但会在NavigationService中引发异常。
This happens when I run the application in my device (Nokia lumia 735). 当我在设备中运行应用程序时(Nokia lumia 735),就会发生这种情况。 When I use the emulator (8.1 wvga 4inch 512mb), the application works nice and the NavigationService works very well! 当我使用仿真器(8.1 wvga 4inch 512mb)时,应用程序运行良好,NavigationService运行良好!
This app is a part of a school project, so I will be very glad if anyone can help me with it. 这个程序是学校项目的一部分,所以如果有人可以帮助我,我将感到非常高兴。
This is my code at this moment: 这是我目前的代码:
The button click code: 按钮的点击代码:
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;
}
and the code for the method that handles the recognized string: 以及处理识别的字符串的方法的代码:
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());
}
}
this is the exception: 这是例外:
{System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component. {System.Exception:错误HRESULT E_FAIL已从对COM组件的调用返回。 at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, String s) at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj) at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value) at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue) at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet) at Microsoft.Phone.Controls.PhoneApplicationFrame.UpdateMargin(Thickness region, PageOrientation orientation) at Microsoft.Phone.Controls.PhoneApplicationFrame.OnVisibleRegionChange(Object sender, VisibleRegionChangeEventArgs args) at Microsoft.P 在MS.Internal.XcpImports.SetValue(IManagedPeerBase doh,DependencyProperty属性,System Object)在MS.Internal.XcpImports.CheckHResult(UInt32 hr)在MS.Internal.XcpImports.SetValue(IManagedPeerBase obj,DependencyProperty属性,String s) System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty属性,EffectiveValueEntry&newEntry,Object newValue)处的Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp,Object value)System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty属性,EffectiveValueEntryValueryryEntry,newEntry,EffectiveValueEntry& System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp,Object value,Boolean allowReadOnlySet)在Microsoft.Phone.Controls.PhoneApplicationFrame.UpdateMargin(Thickness region,PageOrientation direction)在Microsoft.Phone.Controls.PhoneApplicationFrame.OnVisibleRegionChange(Object sender) ,VisibleRegionChangeEventArgs args),位于Microsoft.P hone.Controls.PhoneApplicationFrame.System.Windows.Controls.IFrame.InternalOnVisibleRegionChange(Object sender, VisibleRegionChangeEventArgs args) at System.EventHandler
1.Invoke(Object sender, TEventArgs e) at System.Windows.Controls.Frame.FireEventHandler[T](EventHandler
1 handler, Object sender, T args) at Microsoft.Phone.Controls.PhoneApplicationPage.set_VisibleRegionInPhysicalPixels(RECT value) at Microsoft.Phone.Controls.PhoneApplicationPage.UpdateCurrentVisualState() at Microsoft.Phone.Controls.PhoneApplicationFrame.InternalUpdateOrientationAndMarginForPage(PhoneApplicationPage visiblePage) at Microsoft.Phone.Controls.PhoneApplicationFrame.System.Windows.Controls.IFrame.InternalUpdateOrientationAndMarginForPage(IPhoneApplicationPage visiblePage) at System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject content, NavigationMode mode) at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)} 在System.EventHandler1.Invoke(Object sender, TEventArgs e) at System.Windows.Controls.Frame.FireEventHandler[T](EventHandler
处调用hone.Controls.PhoneApplicationFrame.System.Windows.Controls.IFrame.InternalOnVisibleRegionChange(Object sender,VisibleRegionChangeEventArgs args args)1.Invoke(Object sender, TEventArgs e) at System.Windows.Controls.Frame.FireEventHandler[T](EventHandler
Microsoft.Phone.Controls.PhoneApplicationPage.set_VisibleRegionInPhysicalPixels(RECT值)处的1.Invoke(Object sender, TEventArgs e) at System.Windows.Controls.Frame.FireEventHandler[T](EventHandler
1处理程序,对象发送者,T args)在Microsoft.Phone.Controls.PhoneApplicationFrame.System.Windows.Controls.IFrame.InternalUpdateOrientationAndMarginForPage(IPhoneApplicationPage visiblePage)在System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject content,NavigationMode模式)在System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback IAsyncResult结果)}
This is a confirmed Bug in Windows Phone. 这是Windows Phone中已确认的错误。 Microsoft will fix it in 6-12 months they have told me. 微软会在6到12个月内告知他们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.