我在下面使用的代碼已使用了一年多,現在沒有任何問題。 Google向Google應用發佈更新,現在當speechrecognizer被調用時,它立即停止並返回「網絡錯誤」。我從2015年12月1日卸載更新,所有作品都再次完美。任何人都會遇到這種情況?我還沒有看到任何評論,所以我可能是唯一受影響的人。請看看代碼並告訴我我可能做錯了什麼。Android SpeechRecognizer突然停止網絡錯誤
sr = SpeechRecognizer.createSpeechRecognizer(this.getApplicationContext());
sr.setRecognitionListener(new listener());
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prefCommandKey.toString());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, prefLanguage);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
sr.startListening(intent);
奇怪的部份是一次在一個偉大而這將讓我記錄的東西,然後,當我再次啓動speechrecognizer當它退出了接下來的步驟。有幫助嗎?謝謝。
在執行此操作的時間周圍,您是否正在請求音頻焦點或在代碼中的任何其他位置請求音頻? – brandall