这是我的代码。
speakButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition");
startActivityForResult(intent, REQUEST_CODE);
}
});
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),0);
if(activities.size() == 0){
speakButton.setEnabled(false);
speakButton.setText("Recognizer not present");
}
它在不同设备上的运行方式不同。它在棒棒糖上工作正常,但在豆荚上显示“识别器不存在”。
谢谢