Android的语音语音识别:SpeechRecognizer.startListening(反复呼叫)失败,在JB 4.1.2 [英] Android Speech Speech Recognition: Repeated Calling of SpeechRecognizer.startListening() fails on JB 4.1.2

查看:3543
本文介绍了Android的语音语音识别:SpeechRecognizer.startListening(反复呼叫)失败,在JB 4.1.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在哪里,我踢了一个语音识别听众反复这样我就可以有一个开放式的会议,为用户讲服务。该类也处理问题的果冻豆其中ERROR_SPEECH_TIMEOUT是,如果没有语音听说在5秒内抛出。所以基本上这工作。但是,如果我多次拨打recognizer.startListening(recognizerIntent),它静静地失败就证明了一个事实,即onBeginningOfSpeech()不会被调用在这种情况下。现在,如果我只是不说话,在我所有的果冻豆超时处理程序将每次重新启动监听器没有失败。这似乎onResults后不仅不能()被调用,因为言论被听到。后onResults()被调用,recognizer.startListening(recognizerIntent)肯定是所谓的,但就像我说的,没有任何反应。当它失败,是随机的,没有什么的logcat,表明问题是什么。我只是不知道还有什么尝试。希望你的Andr​​oid语音识别专家之一那里之前已经看到了这一点......

最低:2.2 目标:测试在JB:安卓4.1.2


更多信息(13年11月1日) 4.3更新到我的HTC One肯定已经解决了这个问题。下面我的语音识别服务现已可靠和放大器;准确。我已经运行了至少几分钟,而不会出现错误。至于4.1.2,我更新到4.3之前,它似乎一直在努力更好的(没有谷歌在其最终改变什么?)......我不知道,但它仍然会错过一些话说尽,偶尔没有错误,刚刚停止监听(onBeginningOfSpeech()不会被调用在这种情况下)。我想我只是要提醒我的用户关于Android 4.1.2与关于这个问题,因为我已经就我可以在我的code。

更多信息(13年9月17日) 据说,有一个Android更新(4.3)来HTC那些在九月底(<一href="http://www.ubergizmo.com/2013/09/htc-one-to-receive-android-4-3-jelly-bean-update-this-september/">http://www.ubergizmo.com/2013/09/htc-one-to-receive-android-4-3-jelly-bean-update-this-september/).因此,希望这将解决这个问题,在该设备上的问题,但仍然为我正在运行的是Android 4.1.2,并停留在该版本一会儿应用程序的用户,我还是不知道做什么,在这种情况下,希望这是唯一的Andr​​oid版本这个问题。有什么办法来找出有多少设备都在运行4.1.2 ??

更多信息(13年9月15日) 在这篇文章中的位置:<一href="http://stackoverflow.com/questions/17592333/google-voice-recognizer-doesnt-starts-on-android-4-x?noredirect=1#comment27730909_17592333">Google语音识别器不启动在Android 4.x的。笔者州说,他是在他的HTC One看到这个问题。我也有一类One HTC是我在(安卓4.1.2)看到了这个问题。我不知道这是独一无二的HTC呢? (或者运行Android 4.1.2任何设备) - 我无法证实其难以测试运行JB所有最新的设备。提交人进一步指出,他与盈置4.2.2工作正常。谁能告诉我是什么设备,他们看到这个问题?

更多信息(13年9月8日) 只是为了确认有一个与我的code没有问题,我还测试了这款Android上2.3.3,我是能够调用onResult()> startListening()25次在一排。当目标的Andr​​oid 4.1.2,我从来没有能够得到过去的3或4个电话。我不能相信没有其他人遇到这个问题?

 公共类VoiceRecogService扩展服务
{
    保护AudioManager mAudioManager;
    保护SpeechRecognizer mSpeechRecognizer;
    受保护的意图mSpeechRecognizerIntent;
    保护RecognitionListener mSpeechRecognizerListner;
    //保护的最后使者mServerMessenger =新信使(新IncomingHandler(本));

    保护挥发性布尔mIsListening;
    保护挥发性布尔mIsCountDownOn;

    静态最终诠释MSG_RECOGNIZER_START_LISTENING = 1;
    静态最终诠释MSG_RECOGNIZER_CANCEL = 2;

    私人诠释mBindFlag;
    私人信使mServiceMessenger;

    私人语境m_ctx;

    私人处理程序mHandler =新的处理程序();
    //私人布尔m_bReadyForSpeechReceived = FALSE;

    @覆盖
    公共无效的onCreate()
    {
        super.onCreate();
        m_ctx =这一点;

        mAudioManager =(AudioManager)getSystemService(Context.AUDIO_SERVICE);

        //不要静音蜂鸣当语音听第一次揭开序幕
        Log.d(测试:语音业务:呼叫开始,的onCreate());
        startListening(假);
    }
    私人无效startListening(布尔bMuteSound){
        Log.d(测试:语音业务:startListening(),mIsListening真:假);
        如果(bMuteSound ==真&功放;&安培; Build.VERSION.SDK_INT&GT; = 16)// Build.VERSION_ codeS.JELLY_BEAN)
        {
            //关闭蜂鸣声
            mAudioManager.setStreamMute(AudioManager.STREAM_SYSTEM,真正的);
        }
        如果(!mIsListening)
        {
             //mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
             recognizeSpeechDirectly();
             mIsListening = TRUE;

        }
    }

    ////////////////////////////////////////////////// ///////////////////////
    / **
     *懒惰初始化语音识别器
     * /
    私人SpeechRecognizer getSpeechRecognizer()
    {
        如果(mSpeechRecognizer == NULL)
        {
            mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(m_ctx);
        }
        返回mSpeechRecognizer;
    }
    私人RecognitionListener getSpeechRecognizerListner()
    {
        如果(mSpeechRecognizerListner == NULL)
        {
            mSpeechRecognizerListner =新SpeechRecognitionListener();
        }
        返回mSpeechRecognizerListner;
    }

    私人无效recognizeSpeechDirectly()
    {
        意图recognizerIntent =新的意图(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        //接受部分结果,如果他们来了
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,真正的);

        recognizeSpeechDirectly(m_ctx,recognizerIntent,getSpeechRecognizerListner(),getSpeechRecognizer());
    }
    公共静态无效recognizeSpeechDirectly(上下文的背景下,
                                               意图recognizerIntent,
                                               RecognitionListener监听器,
                                               SpeechRecognizer识别)
    {
        //需要有一个调用包为它工作
        如果(!recognizerIntent.hasExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE))
        {
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGEcom.dummy);
        }

        recognizer.setRecognitionListener(听众);
        recognizer.startListening(recognizerIntent);
    }
    ////////////////////////////////////////////////// //////////////////////////

    公共无效停止()
    {
        如果(getSpeechRecognizer()!= NULL)
        {
            。getSpeechRecognizer()的stopListening();
            getSpeechRecognizer()取消()。
            getSpeechRecognizer()destroy()方法。

            mIsListening = FALSE;
            如果(Build.VERSION.SDK_INT&GT; = 16); // Build.VERSION_ codeS.JELLY_BEAN)
                mAudioManager.setStreamMute(AudioManager.STREAM_SYSTEM,假);
        }
    }

    //为果冻豆解决倒计时
    保护CountDownTimer mNoSpeechCountDown =新CountDownTimer(5000,5000)
    {
        @覆盖
        公共无效onTick(长millisUntilFinished)
        {
            // TODO自动生成方法存根
        }
        @覆盖
        公共无效onFinish()
        {
            mIsCountDownOn = FALSE;
            Log.d(测试:语音业务:呼叫开始,onFinish());
            startListening(真正的);
        }
    };

    @覆盖
    公共无效的onDestroy()
    {
        super.onDestroy();

        如果(mIsCountDownOn)
        {
            mNoSpeechCountDown.cancel();
        }
        如果(mSpeechRecognizer!= NULL)
        {
            mSpeechRecognizer.destroy();
        }
    }

    保护类SpeechRecognitionListener实现RecognitionListener
    {
        @覆盖
        公共无效onReadyForSpeech(包PARAMS)
        {
            如果(Build.VERSION.SDK_INT&GT; = 16)// Build.VERSION_ codeS.JELLY_BEAN)
            {
                mIsCountDownOn =真;
                mNoSpeechCountDown.start();
            }
            Log.d(测试:语音业务,onReadyForSpeech);
        }
        @覆盖
        公共无效onBeginningOfSpeech()
        {
            //语音输入将被处理,所以没有必要向下计数了
            如果(mIsCountDownOn)
            {
                mIsCountDownOn = FALSE;
                mNoSpeechCountDown.cancel();
            }
        }
        @覆盖
        公共无效onEndOfSpeech()
        {
            Log.d(测试:语音业务,onEndOfSpeech);
        }

        @覆盖
        公共无效onBufferReceived(byte []的缓冲区)
        {
            //Log.d("TESTING:语音业务,缓冲区+新的String(新的byte [] {0x63}));
        }

        @覆盖
        公共无效onerror的(INT错误)
        {
            如果((错误== SpeechRecognizer.ERROR_NO_MATCH)
                    || (错误== SpeechRecognizer.ERROR_SPEECH_TIMEOUT)){
                如果(mIsCountDownOn)
                {
                    mIsCountDownOn = FALSE;
                    mNoSpeechCountDown.cancel();
                }
                 mIsListening = FALSE;
                 Log.d(测试:语音业务:呼叫开始,onError的());
                 startListening(真正的);
            }
        }

        @覆盖
        公共无效的onEvent(INT事件类型,捆绑PARAMS)
        {

        }

        @覆盖
        公共无效onPartialResults(包partialResults)
        {

        }

        @覆盖
        公共无效onResults(捆绑结果)
        {
             //字符串str =新的String();
             //Log.d(TAG,onResults+结果);
             ArrayList的数据= results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);

             //如果(data.size()&GT; = 1){
             // //检查保存:
             //}

             的for(int i = 0; I&LT; data.size();我++)
             {
                 Log.d(测试:语音业务,(串)data.get(一));
             }

             //如果没有保存的地方在那里,然后继续:
             如果(mIsCountDownOn)
             {
                 mIsCountDownOn = FALSE;
             }
             mIsListening = FALSE;
             Log.d(测试:语音业务:呼叫开始,onResults());

             startListening(真正的);
        }
        @覆盖
        公共无效onRmsChanged(浮动rmsdB)
        {

        }
    }
    @覆盖
    公众的IBinder onBind(意向为arg0){
        // TODO自动生成方法存根
        返回null;
    }
}
 

解决方案

我在Android 4.4奇巧上的Nexus 5,它有同样的问题。我认为这很可能是Android的bug,因为我还没有看到任何人只要有一个干净的解决方案。照片 该解决方案是类似Andrew_CS解决方案,但我认为它实际上可以更好地识别。安卓的解决方案正在不断启动和停止识别器,你必须保持跟踪事情的状态一样,如果你正在处理语音与否。这一新的解决方案/工作围绕基本上做到这一点:

  • 一旦onResults被称为我们的结果进行处理,我们启动一个定时器。
  • 如果事情都工作正常,onReadyForSpeech将被调用,我们可以取消我们的定时器。
  • 如果事情不能正常工作,我们的计时器结束,我们重新启动了语音识别并重新开始计时。
  • 确保你在你的OnDestroy方法取消计时器也是如此。

请让我知道如果你找到一个更好的方法,但这似乎合作得很好,现在。如果我们实际上可以证明这是一个Android的错误,我很想有人将其提交给谷歌。

  @覆盖
        公共无效onReadyForSpeech(包PARAMS){
            Log.d(演讲,onReadyForSpeech:取消计时器);
            如果(mTimer!= NULL){
                mTimer.cancel();
            }
        }


        @覆盖
        公共无效onResults(捆绑的结果){
            //如果定时器是可用的,取消它,所以它不会打断我们的结果处理
            如果(mTimer!= NULL){
                mTimer.cancel();
            }
            Log.d(演讲,onResults);
            //开始处理数据
            ArrayList的&LT;字符串&GT; strlist = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            的for(int i = 0; I&LT; strlist.size();我++){
                Log.d(演讲,你说:+ strlist.get(一));
            }
            //开始听一次
            Log.d(演讲,onResults:开始听);
            mSpeechRecognizer.startListening(mRecognizerIntent);
            //启动一个定时器的情况下OnReadyForSpeech是从来没有叫回来(Android的错误?)
            Log.d(演讲,onResults:启动一个定时器);
            如果(mTimer == NULL){
                mTimer =新CountDownTimer(2000,500){
                    @覆盖
                    公共无效onTick(长L){
                    }

                    @覆盖
                    公共无效onFinish(){
                        Log.d(演讲,Timer.onFinish:定时器后重新启动识别器);
                        mSpeechRecognizer.cancel();
                        mSpeechRecognizer.startListening(mRecognizerIntent);
                    }
                };
            }
            mTimer.start();
        }
 

I have a service where I'm kicking off a speech recognition listener repeatedly so I can have an open ended session for the user to speak. The class also handles the issue in Jelly Bean where a ERROR_SPEECH_TIMEOUT is thrown if no speech is heard in 5 seconds. So basically this works. However if I repeatedly call recognizer.startListening(recognizerIntent) , it silently fails as evidenced by the fact that onBeginningOfSpeech() is never called in this case. Now IF I just do not talk at all my Jelly Bean timeout handler will restart the listener every time without fail. It seems to only fail after onResults() is called because speech WAS heard. After onResults() is called, recognizer.startListening(recognizerIntent) is definitely called, but like I said, nothing happens. When it fails it is random and there is nothing in Logcat to indicate what the issue is. I just don't know what else to try. Hopefully one of you Android Speech recognition experts out there has seen this before...

Minimum: 2.2 Target: Testing on JB : Android 4.1.2


MORE INFO (11-01-13) The 4.3 Update to my HTC One has definitely addressed this issue. My Speech recognition service below is now reliable & accurate. I has run for at least few minutes without error. As for 4.1.2, before my update to 4.3 it seemed to have been working better (did Google change anything on their end?)...I don't know, but it still would miss some words spoken and occasionally without error, just stop listening (onBeginningOfSpeech() is never called in this case). I suppose I will just have to warn my users about Android 4.1.2 with regards to this issue because I have gone as far as I can go in my code.

MORE INFO (09-17-13) Supposedly, there is an Android update (4.3) coming to HTC ones at the end of September (http://www.ubergizmo.com/2013/09/htc-one-to-receive-android-4-3-jelly-bean-update-this-september/). So hopefully that will address this issue on that device. The issue remains though for my app users that are running Android 4.1.2 and stuck on that version for a while. I still don't know what to do in those cases, and hopefully that is the ONLY Android version with this issue. Is there any way to find out how many devices are running 4.1.2??

MORE INFO (09-15-13) In this post here: Google voice recognizer doesn't starts on Android 4.x. The author state states that he is seeing this issue on his HTC one. I also have an HTC one that I'm seeing this issue on (Android 4.1.2) . I wonder if this is unique to the HTC one? (or any device running Android 4.1.2) - I can't confirm as its difficult to test on all the latest devices running JB. The author further states that his Nexxus with 4.2.2 works fine. Can anyone tell me on what device they see this issue?

MORE INFO (9-08-13) Just to confirm there is no issue with my code, I also tested this on Android 2.3.3 and I was able to call onResult() > startListening() 25 times in a row. When targeting Android 4.1.2 I'm never able to get past 3 or 4 calls. I can't believe no one else has run into this issue?

public class VoiceRecogService extends Service
{
    protected AudioManager mAudioManager; 
    protected SpeechRecognizer mSpeechRecognizer;
    protected Intent mSpeechRecognizerIntent;
    protected RecognitionListener mSpeechRecognizerListner;
    //protected final Messenger mServerMessenger = new Messenger(new IncomingHandler(this));

    protected volatile boolean mIsListening;
    protected volatile boolean mIsCountDownOn;

    static final int MSG_RECOGNIZER_START_LISTENING = 1;
    static final int MSG_RECOGNIZER_CANCEL = 2;

    private int mBindFlag;
    private Messenger mServiceMessenger;

    private Context m_ctx;

    private Handler mHandler = new Handler();
    //private boolean m_bReadyForSpeechReceived = false;

    @Override
    public void onCreate()
    {
        super.onCreate();
        m_ctx = this;

        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 

        //do not mute beep when speech listening first kicks off
        Log.d("TESTING: SPEECH SERVICE: CALL START", "onCreate()"); 
        startListening(false);
    }
    private void startListening(boolean bMuteSound){
        Log.d("TESTING: SPEECH SERVICE: startListening()", mIsListening? "true":"false"); 
        if (bMuteSound==true && Build.VERSION.SDK_INT >= 16)//Build.VERSION_CODES.JELLY_BEAN)
        {
            // turn off beep sound  
            mAudioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
        }
        if (!mIsListening)
        {
             //mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
             recognizeSpeechDirectly ();
             mIsListening = true;

        }
    }

    /////////////////////////////////////////////////////////////////////////
    /**
     * lazy initialize the speech recognizer
     */
    private SpeechRecognizer getSpeechRecognizer()
    {
        if (mSpeechRecognizer == null)
        {
            mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(m_ctx);
        }
        return mSpeechRecognizer;
    }
    private RecognitionListener getSpeechRecognizerListner()
    {
        if (mSpeechRecognizerListner == null)
        {
            mSpeechRecognizerListner = new SpeechRecognitionListener();
        }
        return mSpeechRecognizerListner;
    }

    private void recognizeSpeechDirectly()
    {
        Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        // accept partial results if they come
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);

        recognizeSpeechDirectly(m_ctx,recognizerIntent, getSpeechRecognizerListner(), getSpeechRecognizer());
    }
    public static void recognizeSpeechDirectly(Context context, 
                                               Intent recognizerIntent, 
                                               RecognitionListener listener,
                                               SpeechRecognizer recognizer)
    {
        //need to have a calling package for it to work
        if (!recognizerIntent.hasExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE))
        {
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.dummy");
        }

        recognizer.setRecognitionListener(listener);
        recognizer.startListening(recognizerIntent);
    }
    ////////////////////////////////////////////////////////////////////////////

    public void stop()
    {
        if (getSpeechRecognizer() != null)
        {
            getSpeechRecognizer().stopListening();
            getSpeechRecognizer().cancel();
            getSpeechRecognizer().destroy();

            mIsListening = false;
            if (Build.VERSION.SDK_INT >= 16);//Build.VERSION_CODES.JELLY_BEAN)
                mAudioManager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
        }
    }

    // Count down timer for Jelly Bean work around
    protected CountDownTimer mNoSpeechCountDown = new CountDownTimer(5000, 5000)
    {
        @Override
        public void onTick(long millisUntilFinished)
        {
            // TODO Auto-generated method stub
        }
        @Override
        public void onFinish()
        {
            mIsCountDownOn = false;
            Log.d("TESTING: SPEECH SERVICE: CALL START", "onFinish()"); 
            startListening(true);
        }
    };

    @Override
    public void onDestroy()
    {
        super.onDestroy();

        if (mIsCountDownOn)
        {
            mNoSpeechCountDown.cancel();
        }
        if (mSpeechRecognizer != null)
        {
            mSpeechRecognizer.destroy();
        }
    }

    protected class SpeechRecognitionListener implements RecognitionListener
    {
        @Override
        public void onReadyForSpeech(Bundle params)
        {
            if (Build.VERSION.SDK_INT >= 16)//Build.VERSION_CODES.JELLY_BEAN)
            {
                mIsCountDownOn = true;
                mNoSpeechCountDown.start();
            }
            Log.d("TESTING: SPEECH SERVICE", "onReadyForSpeech"); 
        }
        @Override
        public void onBeginningOfSpeech()
        {
            // speech input will be processed, so there is no need for count down anymore
            if (mIsCountDownOn)
            {
                mIsCountDownOn = false;
                mNoSpeechCountDown.cancel();
            }               
        }
        @Override
        public void onEndOfSpeech()
        {
            Log.d("TESTING: SPEECH SERVICE", "onEndOfSpeech"); 
        }

        @Override
        public void onBufferReceived(byte[] buffer)
        {
            //Log.d("TESTING: SPEECH SERVICE", buffer + new String(new byte[] {0x63})); 
        }

        @Override
        public void onError(int error)
        {
            if ((error == SpeechRecognizer.ERROR_NO_MATCH)
                    || (error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT)){
                if (mIsCountDownOn)
                {
                    mIsCountDownOn = false;
                    mNoSpeechCountDown.cancel();
                }
                 mIsListening = false;
                 Log.d("TESTING: SPEECH SERVICE: CALL START", "onError()"); 
                 startListening(true);
            }
        }

        @Override
        public void onEvent(int eventType, Bundle params)
        {

        }

        @Override
        public void onPartialResults(Bundle partialResults)
        {

        }

        @Override
        public void onResults(Bundle results)
        {
             //String str = new String();
             //Log.d(TAG, "onResults " + results);
             ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);

             //if(data.size() >=1){
             //  //check for save it:
             //}

             for (int i = 0; i < data.size(); i++)
             {
                 Log.d("TESTING: SPEECH SERVICE", (String)data.get(i));
             }

             //if no "save it" somewhere in there, then continue:
             if (mIsCountDownOn)
             {
                 mIsCountDownOn = false;
             }
             mIsListening = false;
             Log.d("TESTING: SPEECH SERVICE: CALL START", "onResults()"); 

             startListening(true);
        }
        @Override
        public void onRmsChanged(float rmsdB)
        {

        }
    }
    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }
}

解决方案

I am on Android 4.4 KitKat on a Nexus 5 and it has this same issue. I think it's likely an Android bug because I haven't seen anyone with a clean solution.
This solution is similar to Andrew_CS solution but I think it's actually allows for better recognition. Andrews solution is constantly starting and stopping the recognizer and you have to keep track of the state of things like if you are processing speech or not. This new solution/work-around basically does this:

  • Once onResults is called and our results are processed, we start a timer.
  • If things are working properly, onReadyForSpeech will be called and we can cancel our timer.
  • If things are not working properly, our timer finishes and we restart the speech recognizer and start the timer again.
  • Make sure you cancel the timer in your OnDestroy method as well.

Please let me know if you find an even better way, but this seems to work really well for now. If we can actually prove this is an Android bug, I'd love for someone to submit it to Google.

            @Override
        public void onReadyForSpeech(Bundle params) {
            Log.d("Speech", "onReadyForSpeech: Cancel Timer");
            if(mTimer != null) {
                mTimer.cancel();
            }
        }


        @Override
        public void onResults(Bundle results) {
            //If the timer is available, cancel it so it doesn't interrupt our result processing
            if(mTimer != null){
                mTimer.cancel();
            }
            Log.d("Speech", "onResults");
            //Start processing data
            ArrayList<String> strlist = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            for (int i = 0; i < strlist.size();i++ ) {
                Log.d("Speech", "YOU SAID: " + strlist.get(i));
            }
            //Start listening again
            Log.d("Speech", "onResults: Start Listening");
            mSpeechRecognizer.startListening(mRecognizerIntent);
            //Start a timer in case OnReadyForSpeech is never called back (Android Bug?)
            Log.d("Speech", "onResults: Start a timer");
            if(mTimer == null) {
                mTimer = new CountDownTimer(2000, 500) {
                    @Override
                    public void onTick(long l) {
                    }

                    @Override
                    public void onFinish() {
                        Log.d("Speech", "Timer.onFinish: Timer Finished, Restart recognizer");
                        mSpeechRecognizer.cancel();
                        mSpeechRecognizer.startListening(mRecognizerIntent);
                    }
                };
            }
            mTimer.start();
        }

这篇关于Android的语音语音识别:SpeechRecognizer.startListening(反复呼叫)失败,在JB 4.1.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆