以下是我的语音识别代码,对于最新的设备和平板电脑,它显示“识别器不存在”。请帮助我如何修复它。
public void startMyVoice()
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, sayClose);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
try
{
startActivityForResult(intent, RESULT_SPEECH);
}
catch (ActivityNotFoundException a)
{
Toast.makeText(getApplicationContext(), "Recogniser not present", Toast.LENGTH_SHORT).show();
}
}
根据this https://developer.android.com/training/package-visibility文档:
当应用面向 Android 11(API 级别 30)或更高版本时...要查看其他包,请使用<queries>
元素。
所以如果你正在使用RecognizerIntent.ACTION_RECOGNIZE_SPEECH
,那么你需要声明相同的intent https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_RECOGNIZE_SPEECH in AndroidManifest.xml
外部<application>
像这样的标签:
<manifest>
...
<queries>
<intent>
<action android:name="android.speech.action.RECOGNIZE_SPEECH" />
</intent>
</queries>
</manifest>
否则pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
将始终返回一个空列表。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)