onError
このようなRecognitionListener
インターフェースを実装できます。それはあなたの活動を継続的に聞いています。
@Override
public void onError(int error) {
String errorMessage = getErrorText(error);
Log.i(Constants.TAG, "FAILED " + errorMessage);
speech.destroy();
speech = null;
StartListening();
}
private void StartListening() {
speech = SpeechRecognizer.createSpeechRecognizer(this);
speech.setRecognitionListener(this);
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
//if setting.SpeechEnable
speech.startListening(recognizerIntent);
}