谷歌语音识别器无法在Android 4.x上启动

编程入门 行业动态 更新时间:2024-10-28 02:34:53
本文介绍了谷歌语音识别器无法在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上启动

本文发布于:2023-11-17 17:03:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1610395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语音识别   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!