Android的RecognizerIntent语音识别
问题描述:
如何处理图像(ImageView的)事件中的RecognizerIntent完成的知名度,由于用户不说话
How to handle the visibility of an image(ImageView) in the event the RecognizerIntent finishes due to the user not speaking
if (RecognizerIntent.EXTRA_RESULTS == null){
image1.setVisibility(View.VISIBLE);///microphone icon
}
或
if (RecognizerIntent.ACTION_RECOGNIZE_SPEECH == null){
image1.setVisibility(View.INVISIBLE);///microphone
}
日Thnx
答
在code以上你只是测试,如果常量是零,而他们没有。你必须用
In the code above you are just testing if the constants are null, which they are not. You have to start the recognition somewhere in the code by
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//... put other settings in the Intent
startActivityForResult(intent, REQUEST_CODE);
和在接收结果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
ArrayList<String> results = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
//... do your stuf with results
}
super.onActivityResult(requestCode, resultCode, data);
}
一个更加个性化的方式是直接使用SpeechRecognizer。例如,见this问题。
A more customizable way is to use SpeechRecognizer directly. See for example this question.