android – 错误ERROR_RECOGNIZER_BUSY与离线语音识别

android – 错误ERROR_RECOGNIZER_BUSY与离线语音识别,第1张

概述我已经对google离线语音识别进行了研究.但它在Google nexus 5( *** 作系统:-4.4)中工作正常,但是如果在三星Galaxy S5(OS:-5.0)中实现,则它不会识别并显示此错误: 8- ERROR_RECOGNIZER_BUSY. 以下是我的代码通过将此链接作为参考,我已经做出了http://www.truiton.com/2014/06/android-speech-recog 我已经对Google离线语音识别进行了研究.但它在Google nexus 5( *** 作系统:-4.4)中工作正常,但是如果在三星galaxy S5(OS:-5.0)中实现,则它不会识别并显示此错误:

8- ERROR_RECOGNIZER_BUSY.

以下是我的代码通过将此链接作为参考,我已经做出了http://www.truiton.com/2014/06/android-speech-recognition-without-dialog-custom-activity/的修改

没有互联网的声音必须承认.我已经在口袋狮身人面像上工作,但是它需要很多方面的声音,所以客户端已经拒绝了.

public class VoiceRecognitionActivity extends Activity implements RecognitionListener {    private TextVIEw returnedText;    private static Progressbar progressbar;    private static SpeechRecognizer speech = null;    private static Intent recognizerIntent;    private String LOG_TAG = "VoiceRecognitionActivity";    private button button1;    Activity activity = VoiceRecognitionActivity.this;    private TextVIEw textVIEw2;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        returnedText = (TextVIEw) findVIEwByID(R.ID.textVIEw1);        textVIEw2 = (TextVIEw) findVIEwByID(R.ID.textVIEw2);        progressbar = (Progressbar) findVIEwByID(R.ID.progressbar1);        button1 = (button) findVIEwByID(R.ID.button1);         getwindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);    //  togglebutton = (Togglebutton) findVIEwByID(R.ID.togglebutton1);         PackageManager pm = getPackageManager();         List<ResolveInfo> activitIEs = pm.queryIntentActivitIEs( new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),0);         if (activitIEs.size() != 0)          {             createSpeechAgain(VoiceRecognitionActivity.this);         }          else          {             textVIEw2.setText("Recognizer_not_present");         }        button1.setonClickListener(new OnClickListener() {                      @OverrIDe            public voID onClick(VIEw arg0) {                speech.stopListening();                speech.destroy();                createSpeechAgain(VoiceRecognitionActivity.this);            }        });    }    private  voID createSpeechAgain(VoiceRecognitionActivity voiceRecognitionActivity) {        progressbar.setVisibility(VIEw.INVISIBLE);        speech = SpeechRecognizer.createSpeechRecognizer(voiceRecognitionActivity);        speech.setRecognitionListener(voiceRecognitionActivity);        recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);        recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,"en-US");        recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALliNG_PACKAGE,voiceRecognitionActivity.getPackagename());        recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);        recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESulTS,3);        //recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFliNE,Boolean.FALSE);        recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_input_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILliS,20000);        recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_input_COMPLETE_SILENCE_LENGTH_MILliS,20000);        // EXTRA_PREFER_OFFliNE        progressbar.setVisibility(VIEw.VISIBLE);        progressbar.setIndeterminate(true);        speech.startListening(recognizerIntent);    }    @OverrIDe    public voID onResume() {        super.onResume();    }    @OverrIDe    protected voID onPause() {        super.onPause();        /*if (speech != null) {            speech.destroy();            Log.i(LOG_TAG,"destroy");        }*/    }    @OverrIDe    public voID onBeginningOfSpeech() {        Log.i(LOG_TAG,"onBeginningOfSpeech");        progressbar.setIndeterminate(false);        progressbar.setMax(10);    }    @OverrIDe    public voID onBufferReceived(byte[] buffer) {        Log.i(LOG_TAG,"onBufferReceived: " + buffer);    }    @OverrIDe    public voID onEndOfSpeech() {        Log.i(LOG_TAG,"onEndOfSpeech");        progressbar.setIndeterminate(false);        progressbar.setVisibility(VIEw.INVISIBLE);        speech.stopListening();    }    @OverrIDe    public voID onError(int errorCode) {        String errorMessage = getErrorText(errorCode);        Log.d(LOG_TAG,"Failed " + errorMessage);        textVIEw2.setText(errorMessage);    }    @OverrIDe    public voID onEvent(int arg0,Bundle arg1) {        Log.i(LOG_TAG,"onEvent");    }    @OverrIDe    public voID onPartialResults(Bundle arg0) {        Log.i(LOG_TAG,"onPartialResults");    }    @OverrIDe    public voID onReadyForSpeech(Bundle arg0) {        Log.i(LOG_TAG,"onReadyForSpeech");    }    @OverrIDe    public voID onResults(Bundle results) {        Log.i(LOG_TAG,"onResults");        ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESulTS_RECOGNITION);        String text = "";        for (String result : matches)            text += result + "\n";        returnedText.setText(text);        Log.v(LOG_TAG,"onResults---> " + text);        progressbar.setVisibility(VIEw.VISIBLE);        progressbar.setIndeterminate(true);        speech.startListening(recognizerIntent);    }    @OverrIDe    public voID onRmsChanged(float rmsdB) {        //Log.i(LOG_TAG,"onRmsChanged: " + rmsdB);        progressbar.setProgress((int) rmsdB);    }    public String getErrorText(int errorCode) {        String message;        switch (errorCode) {        case SpeechRecognizer.ERROR_AUdio:            message = "Audio recording error";            Log.v("LOG_TAG",message);            progressbar.setVisibility(VIEw.VISIBLE);            progressbar.setIndeterminate(true);            speech.startListening(recognizerIntent);            break;        case SpeechRecognizer.ERROR_CLIENT:            message = "ClIEnt sIDe error";            Log.v("LOG_TAG",message);            progressbar.setVisibility(VIEw.VISIBLE);            progressbar.setIndeterminate(true);            speech.startListening(recognizerIntent);            break;        case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:            message = "InsufficIEnt permissions";            Log.v("LOG_TAG",message);            progressbar.setVisibility(VIEw.VISIBLE);            progressbar.setIndeterminate(true);            speech.startListening(recognizerIntent);            break;        case SpeechRecognizer.ERROR_NETWORK:            message = "Network error";            Log.v("LOG_TAG",message);            break;        case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:            message = "Network timeout";            Log.v("LOG_TAG",message);            break;        case SpeechRecognizer.ERROR_NO_MATCH:            message = "No match";            Log.v("LOG_TAG",message);            progressbar.setVisibility(VIEw.VISIBLE);            progressbar.setIndeterminate(true);            speech.startListening(recognizerIntent);            break;        case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:            message = "RecognitionService busy";            Log.v("LOG_TAG",message);            speech.stopListening();            speech.destroy();            createSpeechAgain(VoiceRecognitionActivity.this);            break;        case SpeechRecognizer.ERROR_SERVER:            message = "error from server";            Log.v("LOG_TAG",message);            break;        case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:            message = "No speech input";            Log.v("LOG_TAG",message);            progressbar.setVisibility(VIEw.VISIBLE);            progressbar.setIndeterminate(true);            speech.stopListening();            speech.destroy();            createSpeechAgain(VoiceRecognitionActivity.this);            break;        default:            message = "DIDn't understand,please try again.";            break;        }        return message;    }   }

Xml: –

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical" >    <ImageVIEw        androID:ID="@+ID/imageVIEw1"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignParentBottom="true"        androID:layout_centerHorizontal="true"        androID:src="@drawable/ic_launcher" />    <Progressbar        androID:ID="@+ID/progressbar1"                androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_alignParentleft="true"        androID:layout_below="@+ID/togglebutton1"        androID:layout_margintop="28dp"        androID:paddingleft="10dp"        androID:paddingRight="10dp" />    <TextVIEw        androID:ID="@+ID/textVIEw1"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_below="@+ID/progressbar1"        androID:layout_centerHorizontal="true"        androID:layout_margintop="47dp" />    <button        androID:ID="@+ID/button1"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_above="@+ID/imageVIEw1"        androID:layout_alignleft="@+ID/imageVIEw1"        androID:text="Restart" />    <TextVIEw        androID:ID="@+ID/textVIEw2"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_above="@+ID/button1"        androID:layout_centerHorizontal="true"        androID:layout_marginBottom="19dp"        androID:text="" />    </relativeLayout>

AndroIDManifest.xml中

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.example.offlineGooglespeechtotext"    androID:versionCode="1"    androID:versionname="1.0" >    <uses-sdk        androID:minSdkVersion="19"        androID:targetSdkVersion="19" />    <uses-permission androID:name="androID.permission.RECORD_AUdio" />    <application        androID:allowBackup="true"        androID:icon="@drawable/ic_launcher"        androID:label="@string/app_name"        androID:theme="@style/Apptheme" >        <activity            androID:name=".VoiceRecognitionActivity"            androID:label="@string/app_name" >            <intent-filter>                <action androID:name="androID.intent.action.MAIN" />                <category androID:name="androID.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

logcat的: –

09-30 18:05:54.732: D/ResourcesManager(3941): creating new AssetManager and set to /data/app/com.example.offlineGooglespeechtotext-2/base.apk09-30 18:05:54.772: V/BitmapFactory(3941): DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/sym_def_app_icon.png09-30 18:05:54.772: V/BitmapFactory(3941): DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi/ic_launcher.png09-30 18:05:54.787: V/BitmapFactory(3941): DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/ic_ab_back_holo_dark_am.png09-30 18:05:54.797: V/BitmapFactory(3941): DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/sym_def_app_icon.png09-30 18:05:54.817: D/Activity(3941): performCreate Call secproduct feature valuefalse09-30 18:05:54.817: D/Activity(3941): performCreate Call deBUG elastic valuetrue09-30 18:05:54.827: D/Openglrenderer(3941): Render dirty regions requested: true09-30 18:05:54.867: I/(3941): PLATFORM VERSION : JB-MR-209-30 18:05:54.867: I/Openglrenderer(3941): Initialized EGL,version 1.409-30 18:05:54.877: I/Openglrenderer(3941): hwui protection enabled for context,&this =0xb39090d8,&mEgldisplay = 1,&mEglConfig = -1282088012 09-30 18:05:54.887: D/Openglrenderer(3941): Enabling deBUG mode 009-30 18:05:54.957: V/LOG_TAG(3941): No match09-30 18:05:54.957: D/VoiceRecognitionActivity(3941): Failed No match09-30 18:05:54.982: I/Timeline(3941): Timeline: Activity_IDle ID: androID.os.BinderProxy@24862afe time:583737509-30 18:05:55.607: I/VoiceRecognitionActivity(3941): onReadyForSpeech09-30 18:05:55.947: I/VoiceRecognitionActivity(3941): onBeginningOfSpeech09-30 18:05:57.252: I/VoiceRecognitionActivity(3941): onEndOfSpeech09-30 18:05:57.322: V/LOG_TAG(3941): No match09-30 18:05:57.322: D/VoiceRecognitionActivity(3941): Failed No match09-30 18:05:57.332: V/LOG_TAG(3941): No match09-30 18:05:57.332: D/VoiceRecognitionActivity(3941): Failed No match09-30 18:05:57.347: V/LOG_TAG(3941): No match09-30 18:05:57.347: D/VoiceRecognitionActivity(3941): Failed No match09-30 18:05:57.367: V/LOG_TAG(3941): RecognitionService busy09-30 18:05:57.392: D/VoiceRecognitionActivity(3941): Failed RecognitionService busy09-30 18:05:57.392: E/SpeechRecognizer(3941): not connected to the recognition service09-30 18:05:58.232: I/VoiceRecognitionActivity(3941): onReadyForSpeech09-30 18:06:03.287: V/LOG_TAG(3941): No speech input09-30 18:06:03.302: D/VoiceRecognitionActivity(3941): Failed No speech input09-30 18:06:03.302: E/SpeechRecognizer(3941): not connected to the recognition service
解决方法 当您没有密切关闭SpeechRecognizer时,通常会抛出ERROR_RECOGNIZER_BUSY.哟可能已经在使用SpeechRecognizer的一个实例了.

见这http://developer.android.com/reference/android/speech/SpeechRecognizer.html

总结

以上是内存溢出为你收集整理的android – 错误ERROR_RECOGNIZER_BUSY与离线语音识别全部内容,希望文章能够帮你解决android – 错误ERROR_RECOGNIZER_BUSY与离线语音识别所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1132650.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存