谷歌语音识别器无法在Android 4.x上启动 [英] Google voice recognizer doesn't start on Android 4.x

查看:32
本文介绍了谷歌语音识别器无法在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上启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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