谷歌的语音识别器不启动在Android 4.x版 [英] Google voice recognizer doesn't starts on Android 4.x

查看:239
本文介绍了谷歌的语音识别器不启动在Android 4.x版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现这个问题随机...
这里是我的code

I stumbled with this random issue... Here is my code

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():

Method 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()之后mSpeechRecognizer.startListening(意向)和onBeginningOfSpeech()方法的有时不叫。同时onEndOfSpeech(),也可以不叫。

Main issue that is "onReadyForSpeech()" and "onBeginningOfSpeech()" methods sometimes doesn't called after mSpeechRecognizer.startListening(intent). Also "onEndOfSpeech()" also can be not called.

我使用的Nexus 4采用Android 4.2.2

I'm using Nexus 4 with Android 4.2.2

推荐答案

好像是我已经解决我的问题。主要思路来解决的就是保持SpeechRecognizer对象的单个实例而不是每次都重新创建即可。这些改变之后,我没有得到任何​​识别忙错​​误。但我的HTC One S当我用我的应用程序仍然冻结。我不明白为什么...

Seems to be I've fixed my problem. Main idea to fix is keep single instance of SpeechRecognizer object instead of recreating it each time. After these changes I didn't get any "Recognizer busy" error. But my HTC One S still freezes when I use my app. I could not understand why...

这篇关于谷歌的语音识别器不启动在Android 4.x版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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