2013-12-24 2 views
0

Я использую голосовую функцию поиска в моем app.For этого я использовал, чтобы начать распознаватель речи с помощью Intent, как: -java.io.IOException: не может начать запись

iSpeechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
iSpeechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
iSpeechIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "voice.recognition.test");  
iSpeechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3); 

            sr.startListening(iSpeechIntent); 

Теперь я получил это исключение:

-ERROR|12-11 18:56:44.035|4053|4067||RecognitionControllerImpl|Caused by: java.io.IOException: couldn't start recording 
ERROR|12-11 18:56:44.035|4053|4067||RecognitionControllerImpl| at java.io.BufferedInputStream.read(BufferedInputStream.java:324) 
ERROR|12-11 18:56:44.035|4053|4067||RecognitionControllerImpl| at com.google.android.voicesearch.speechservice.RecognitionControllerImpl$1.handleMessage(RecognitionControllerImpl.java:251) 
ERROR|12-11 18:56:44.035|4053|4067||RecognitionControllerImpl| at android.os.HandlerThread.run(HandlerThread.java:60) 
ERROR|12-11 18:56:44.035|4053|4067||RecognitionControllerImpl| at android.os.Looper.loop(Looper.java:123) 
ERROR|12-11 18:56:44.035|4053|4067||RecognitionControllerImpl| at com.google.android.voicesearch.speechservice.RecognitionControllerImpl.recordAndSend(RecognitionControllerImpl.java:522) 
ERROR|12-11 18:56:44.035|4053|4067||RecognitionControllerImpl| at android.media.AmrInputStream.read(AmrInputStream.java:88) 
ERROR|12-11 18:56:44.035|4053|4067||RecognitionControllerImpl| at com.google.android.voicesearch.speechservice.RecognitionControllerImpl.access$100(RecognitionControllerImpl.java:82) 
ERROR|12-11 18:56:44.035|4053|4067||RecognitionControllerImpl| at com.google.android.voicesearch.speechservice.AudioBuffer.access$000(AudioBuffer.java:34) 

Мой вопрос: как я могу справиться с этим исключением с помощью дескриптора исключений Uncaught?

+0

Привет, Дипак, у меня такая же проблема, если вам удалось выяснить причину/решение? – MegaAppBear

ответ

0

Изменить ecognizerIntent.LANGUAGE_MODEL_FREE_FORM

В RecognizerIntent.LANGUAGE_MODEL_FREE_FORM

Может быть, это вызывает ошибку.

и удалите следующие лайн-

sr.startListening(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)); 
0

Если вы хотите UncaughtExceptionHandler, HTH:

private UnexpectedTerminationStuff mUnexpectedTerminationStuff = new UnexpectedTerminationStuff(); 
private class UnexpectedTerminationStuff { 
    private Thread mThread; 
    private Thread.UncaughtExceptionHandler mOldUncaughtExceptionHandler = null; 
    private Thread.UncaughtExceptionHandler mUncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() { 
     @Override 
     public void uncaughtException(Thread thread, Throwable ex) { 
      // gets handled in the same thread (main) 
      Log.i(TAG, "uncaught exception in the thread '"+ thread.getName()+ "' (id="+thread.getId() + "), closing the camera"); 
      Log.i(TAG, "handled in the thread '"+ Thread.currentThread().getName()+ "' (id="+Thread.currentThread().getId() + ")"); 
      ex.printStackTrace(); 

      // ..... 
      // CLOSE SOMETHING 
      // ...... 

      Log.i(TAG, "going to execute the previous handler: "+mOldUncaughtExceptionHandler); 
      if(mOldUncaughtExceptionHandler != null) { 
       // it displays the "force close" dialog 
       mOldUncaughtExceptionHandler.uncaughtException(thread, ex); 
      } 
     } 
    }; 
    void init() { 
     mThread = Thread.currentThread(); 
     UncaughtExceptionHandler oldUncaughtExceptionHandler = mThread.getUncaughtExceptionHandler(); 
     if (oldUncaughtExceptionHandler != mUncaughtExceptionHandler) { 
      mOldUncaughtExceptionHandler = oldUncaughtExceptionHandler; 
      mThread.setUncaughtExceptionHandler(mUncaughtExceptionHandler); 
      Log.d(TAG,"~~~ UnexpectedTermination init stuff, doing setUncaughtExceptionHandler"); 
     } else { 
      Log.d(TAG,"~~~ UnexpectedTermination init stuff, skipping setUncaughtExceptionHandler"); 
     } 
     Log.d(TAG,"~~~ UnexpectedTermination init stuff, mThread="+mThread+" mOldUncaughtExceptionHandler="+mOldUncaughtExceptionHandler); 
    } 
    void fini() { 
     Log.d(TAG,"~~~ UnexpectedTermination windup stuff, mThread="+mThread+" mOldUncaughtExceptionHandler="+mOldUncaughtExceptionHandler); 
     if (mThread != null) { 
      mThread.setUncaughtExceptionHandler(mOldUncaughtExceptionHandler); 
      mOldUncaughtExceptionHandler = null; 
      mThread = null; 
     } 
    } 
} 

Чтобы использовать его, называют mUnexpectedTerminationStuff.init() и mUnexpectedTerminationStuff.fini() в соответствующих местах, и заменить «ЗАКРЫТЬ КОЕ »комментировать что-то полезное.

Смежные вопросы