2012-09-06 200 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