2012-09-06 153 views
0

如何处理的图像(ImageView的)事件的RecognizerIntent完成的知名度,由于用户不说话的Android RecognizerIntent语音识别

if (RecognizerIntent.EXTRA_RESULTS == null){ 
image1.setVisibility(View.VISIBLE);///microphone icon 
} 

if (RecognizerIntent.ACTION_RECOGNIZE_SPEECH == null){ 
image1.setVisibility(View.INVISIBLE);///microphone 
} 

日Thnx

回答

9

在上面的代码中,你只是测试常量是否为空,而不是。你必须通过

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 question

+0

很好。谢谢!!非常感激 – user1446988