Java android中的语音识别时间过快
此函数启动语音识别,但超时太快,似乎是语音识别 是从输入法键盘(如谷歌键盘)启动的,它不会很快超时。 我需要一种方法来启动谷歌键盘使用的相同意图Java android中的语音识别时间过快,java,android,Java,Android,此函数启动语音识别,但超时太快,似乎是语音识别 是从输入法键盘(如谷歌键盘)启动的,它不会很快超时。 我需要一种方法来启动谷歌键盘使用的相同意图 public void StartSpeechRecognitionActivity(){ try{ Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.E
public void StartSpeechRecognitionActivity(){
try{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 3000);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 3000);
main.startActivityForResult(intent, SPEECHRECOGNITION_RESULTCODE);
} catch (ActivityNotFoundException error) {
ShowAndSpeakMessage("Speech recognition is not supported by your device");
} catch( RuntimeException error ) {
Log.e( TAG, ERROR_PREFIX + Errors.toString(error) );
} catch( Error error ) {
Log.e( TAG, ERROR_PREFIX + Errors.toString(error) );
throw error;
}
}
这对我来说很好 那么我认为您需要执行check-in-onError函数。我将按以下方式执行此操作。这对我来说很好
public void onError(int error) {
String errorMessage = getErrorText(error);
Log.d(LOG_TAG+">"+ "FAILED " + errorMessage);
if(errorMessage.contains("RecognitionService busy"))
{ speech.stopListening();
speech.startListening(recognizerIntent);
}else if(errorMessage.contains("No speech input")){
speech.stopListening();
speech.startListening(recognizerIntent);
}else if(errorMessage.contains("No match")){
speech.stopListening();
speech.startListening(recognizerIntent);
}
}
因此,您可以尽可能多地检查错误类型,或者您的案例中可能存在错误
我希望它能帮助您不,它不是我真正想要的,这个意图在几秒钟后超时,而我想要的意图将一直打开,直到用户取消
public void onError(int error) {
String errorMessage = getErrorText(error);
Log.d(LOG_TAG+">"+ "FAILED " + errorMessage);
if(errorMessage.contains("RecognitionService busy"))
{ speech.stopListening();
speech.startListening(recognizerIntent);
}else if(errorMessage.contains("No speech input")){
speech.stopListening();
speech.startListening(recognizerIntent);
}else if(errorMessage.contains("No match")){
speech.stopListening();
speech.startListening(recognizerIntent);
}
}