我正在爲使用語音識別的Windows Phone 8.1開發應用程序。 此時,我想使用語音命令在應用程序中導航。該應用程序有一個按鈕來激活語音識別。Windows Phone 8.1語音識別+導航服務問題
我現在的問題是在NavigationService.Navigate。 當我按下按鈕時,應用程序會識別我的語音語音(如「設置」),但會在NavigationService中引發異常。
當我在我的設備(諾基亞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:錯誤HRESULT E_FAIL已經從對COM組件的調用中返回。 在MS.Internal.XcpImports.CheckHResult(UInt32的小時) 在MS.Internal.XcpImports.SetValue(IManagedPeerBase OBJ,的DependencyProperty屬性,字符串或多個) 在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 operation) at System.Windows.DependencyObject.SetValueInternal(DependencyProp erty 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.Phone .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.InternalUpdateOrien tationAndMarginForPage(的PhoneApplicationPage visiblePage) 在Microsoft.Phone.Controls.PhoneApplicationFrame.System.Windows.Controls.IFrame.InternalUpdateOrientationAndMarginForPage(IPhoneApplicationPage visiblePage) 在System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject的內容,NavigationMode模式) 在系統。 Windows.Navigation.NavigationService。ContentLoader_BeginLoad_Callback(IAsyncResult的結果)}
什麼是例外? – aloisdg
@aloisdg我已經更新了任務是例外。 你能幫我嗎? 謝謝 – user3178157
你就可以開始嘗試[這](http://www.telerik.com/forums/exception-error-hresult-e-fail-has-been-returned-from-a-call-to-a -com-component)? – aloisdg