android-SpeechRecognizer权限不足错误与玻璃

android-SpeechRecognizer权限不足错误与玻璃,第1张

概述我正在使用GDK速览来构建应用程序,并且无法在沉浸式应用程序中使语音识别正常工作.这是我的第一个android项目.我试图遵循此:HowcanIusespeechrecognitionwithouttheannoyingdialoginandroidphones在取得初步进展之后,我遇到了一个问题,其中RecognitionListener类抛出

我正在使用GDK速览来构建应用程序,并且无法在沉浸式应用程序中使语音识别正常工作.这是我的第一个android项目.

我试图遵循此:How can I use speech recognition without the annoying dialog in android phones

在取得初步进展之后,我遇到了一个问题,其中RecognitionListener类抛出错误9,权限不足.

我正在使用GDK,它是AndroID-15.

Recognizer的初始化在我的onCreate()方法中:

sr = SpeechRecognizer.createSpeechRecognizer(this);       sr.setRecognitionListener(new Listener()); 

收到点击回调时,我开始监听:

private GestureDetector createGestureDetector(Context context) {        GestureDetector gestureDetector = new GestureDetector(context);        //Create a base Listener for generic gestures        gestureDetector.setBaseListener( new GestureDetector.BaseListener() {            @OverrIDe            public boolean onGesture(Gesture gesture) {//              Log.info(gesture.name());                if (gesture == Gesture.TAP) {                    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,"voice.recognition.test");                    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESulTS,5);                     sr.startListening(intent);                    return true;                }                return false;            }        });        return gestureDetector;    }

这是我的侦听器类的定义:

class Listener implements RecognitionListener              {        public voID onReadyForSpeech(Bundle params)        {            Log.d(TAG, "onReadyForSpeech");        }        public voID onBeginningOfSpeech()        {             Log.d(TAG, "onBeginningOfSpeech");        }        public voID onRmsChanged(float rmsdB)        {             Log.d(TAG, "onRmsChanged");        }        public voID onBufferReceived(byte[] buffer)        {             Log.d(TAG, "onBufferReceived");        }        public voID onEndOfSpeech()        {             Log.d(TAG, "onEndofSpeech");        }        public voID one rror(int error)        {             Log.d(TAG,  "error " +  error);//               mText.setText("error " + error);        }        public voID onResults(Bundle results)                           {             String str = new String();             Log.d(TAG, "onResults " + results);             ArrayList<String> data = results.getStringArrayList(SpeechRecognizer.RESulTS_RECOGNITION);             for (int i = 0; i < data.size(); i++)             {                       Log.d(TAG, "result " + data.get(i));                       str += data.get(i);             }//               mText.setText("results: "+String.valueOf(data.size()));                }        public voID onPartialResults(Bundle partialResults)        {             Log.d(TAG, "onPartialResults");        }        public voID onEvent(int eventType, Bundle params)        {             Log.d(TAG, "onEvent " + eventType);        }    }

这是我的清单文件:

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.example.medicalglass"    androID:versionCode="1"    androID:versionname="1.0" >    <uses-sdk        androID:minSdkVersion="15"        androID:targetSdkVersion="15" />    <application        androID:allowBackup="true"        androID:icon="@drawable/ic_launcher"        androID:label="@string/app_name"        androID:theme="@style/Apptheme" >        <activity            androID:name="com.example.medicalglass.MainActivity"            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>

@R_301_6825@出现后,我立即调用“开始监听”,将以错误代码9调用监听器的onError方法,这表示权限不足.如果有人对androID语音命令或玻璃语音命令有任何经验,并且知道为什么这继续失败,我将不胜感激.谢谢.

解决方法:

首先更改此代码:

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,"voice.recognition.test");

对此代码:

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, getApplication().getPackagename());speechRecognizer.startListening(intent);

编辑:
将此添加到您的清单:

<uses-permission androID:name="androID.permission.RECORD_AUdio" />

如果有错误,请通过LogCat.

总结

以上是内存溢出为你收集整理的android-SpeechRecognizer权限不足错误与玻璃全部内容,希望文章能够帮你解决android-SpeechRecognizer权限不足错误与玻璃所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存