Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android java.io.IOException:无法';不要开始录音_Android - Fatal编程技术网

Android java.io.IOException:无法';不要开始录音

Android java.io.IOException:无法';不要开始录音,android,Android,我正在我的应用程序中使用语音搜索功能。为此,我使用以下意图启动语音识别器:- iSpeechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); iSpeechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); iSpeechIntent.putExtra(RecognizerI

我正在我的应用程序中使用语音搜索功能。为此,我使用以下意图启动语音识别器:-

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)

我的问题是如何使用未捕获的异常句柄处理此异常?

更改
ecognizerIntent.LANGUAGE\u MODEL\u FREE\u FORM

进入
RecognizerIntent.LANGUAGE\u MODEL\u FREE\u FORM

也许这是造成错误的原因

并删除以下行-

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

如果您想要一个
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;
        }
    }
}

要使用它,请在适当的位置调用
muneExpectedTerminationsTuff.init()
muneExpectedTerminationsTuff.fini()
,并将“CLOSE SOMETHING”注释替换为有用的注释。

嗨,Deepak,我遇到了同样的问题,想知道您是否找到了原因/解决方案?