更新(我误读了原始问题)
SpeechRecognizer 不是执行语音处理的对象,但是,传递给 SpeechRecognizer 的 Intent 是 (via )。该意图使用和AFAIK,可以以老式的方式检测。startListening(Intent intent)
RecognizerIntent.ACTION_RECOGNIZE_SPEECH
要检测默认值,请尝试解析您希望查找默认值但具有集合的 Intent。PackageManager.MATCH_DEFAULT_ONLY
未经测试的代码:
String detectDefaultSpeechRecognizer(Context context) {
final Intent speechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// 1: Try to find the default speech intent
final ResolveInfo defaultResolution = context.getPackageManager().resolveService(speechIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (defaultResolution != null) {
final ActivityInfo activity = defaultResolution.activityInfo;
if (!activity.name.equals("com.android.internal.app.ResolverActivity")) {
//ResolverActivity was launched so there is no default speech recognizer
return "";
}
}
// 2: Try to find anything that we can launch speech recognition with. Pick up the first one that can.
final List<ResolveInfo> resolveInfoList = context.getPackageManager().queryIntentServices(speechIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (!resolveInfoList.isEmpty()) {
speechIntent.setClassName(resolveInfoList.get(0).activityInfo.packageName, resolveInfoList.get(0).activityInfo.name);
return resolveInfoList.get(0).activityInfo.packageName;
}
return "";
}
旧答案
看看GAST,它有一种方法可以检查语音识别器中是否支持某种语言。
https://github.com/gast-lib/gast-lib/blob/master/library/src/root/gast/speech/SpeechRecognizingActivity.java#L70
您也可以尝试手动检查元数据标记。http://developer.android.com/reference/android/speech/RecognitionService.html#SERVICE_META_DATA<recognition-service>