本文介绍了谷歌语音识别器无法在Android 4.x上启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我碰巧遇到了这个随机问题... 以下是我的代码
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(mContext); initializeRecognitionListener(); mSpeechRecognizer.setRecognitionListener(mRecognitionListener); Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName()); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US"); intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, Long.valueOf(3000L)); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5); mSpeechRecognizer.startListening(intent);方法InitializeRecognitionListener():
private void initializeRecognitionListener() { mRecognitionListener = new RecognitionListener() { @Override public void onReadyForSpeech(Bundle params) { Log.d("onReadyForSpeech()", "onReadyForSpeech!"); isRecognizing = true; } @Override public void onBeginningOfSpeech() { Log.d("onBeginningOfSpeech()", "onBeginningOfSpeech!"); } @Override public void onEndOfSpeech() { Log.e("onEndOfSpeech()", "onEndOfSpeech! stop SCO"); } ... }主要问题是"onReadyForSpeech()"和"onBeginningOfSpeech()"方法有时在mSpeechRecognizer.startListening(Intent)之后不调用。此外,也不能调用"onEndOfSpeech()"。
我使用的是Nexus 4和Android 4.2.2
推荐答案似乎我已经解决了我的问题。修复的主要思想是保留SpeechRecognizer对象的单个实例,而不是每次都重新创建它。在这些更改之后,我没有收到任何"Recognizer BUSY"错误。但当我使用我的应用程序时,我的HTC One S仍然死机。我不明白为什么...
更多推荐
谷歌语音识别器无法在Android 4.x上启动
发布评论