2016-09-27 80 views
0

我正在使用简单的语音识别。从文本视图中的语音识别打印文本,第一个除外

我知道它成功地工作。

可以说我讲“备注嘿,这是堆栈溢出”

我要排除“备注”,并打印文本的休息一个TextView。

以下是我的工作onActivityResult: -

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE) 

     //If Voice recognition is successful then it returns RESULT_OK 
     if(resultCode == RESULT_OK) { 

      ArrayList<String> textMatchList = data 
        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 

      if (!textMatchList.isEmpty()) { 
       if(textMatchList.get(0).contains("Field")) 
       { 
        Intent non_field = new Intent(DashboardActivity.this,NonFieldActivity.class); 
        startActivity(non_field); 
       } 
       else if(textMatchList.get(0).contains("Tour")) 
       { 
        Intent non_field = new Intent(DashboardActivity.this,TourPlanActivity.class); 
        startActivity(non_field); 
       } 
       else { 
        final Dialog list_dialog; 
        ListView voice_match_list; 
        list_dialog = new Dialog(this); 
        list_dialog.setTitle("Matches"); 
        list_dialog.setCancelable(true); 
        list_dialog.setContentView(R.layout.voice_list_dialog); 
        voice_match_list = (ListView) list_dialog.findViewById(R.id.voice_list); 
        voice_match_list.setAdapter(new ArrayAdapter<String>(this, 
          android.R.layout.simple_list_item_1, 
          textMatchList)); 
        Button cancel_button = (Button) list_dialog.findViewById(R.id.cancel_button_voice); 
        assert cancel_button != null; 
        cancel_button.setOnClickListener(new View.OnClickListener() { 

         @Override 
         public void onClick(View v) { 

          list_dialog.dismiss(); 
         } 
        }); 
        list_dialog.show(); 
       } 

      } 
      //Result code for various error. 
     }else if(resultCode == RecognizerIntent.RESULT_AUDIO_ERROR){ 
      showToastMessage("Audio Error"); 
     }else if(resultCode == RecognizerIntent.RESULT_CLIENT_ERROR){ 
      showToastMessage("Client Error"); 
     }else if(resultCode == RecognizerIntent.RESULT_NETWORK_ERROR){ 
      showToastMessage("Network Error"); 
     }else if(resultCode == RecognizerIntent.RESULT_NO_MATCH){ 
      showToastMessage("No Match"); 
     }else if(resultCode == RecognizerIntent.RESULT_SERVER_ERROR){ 
      showToastMessage("Server Error"); 
     } 
     super.onActivityResult(requestCode, resultCode, data); 
    } 
    /** 
    * Helper method to show the toast message 
    **/ 
    void showToastMessage(String message){ 
     Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); 
    } 

我的研究,从谷歌: -

.replace可以在这里很有用,不能够了解如何与我的代码中使用它。有人可以提供我的文章或帮助我确定逻辑吗?

回答

2

你可以通过拆分方法来完成。

String message = "Remark hey this is stack overflow"; 
String [] arr = message.split(" ", 2); 

现在arr[0]将包含"Remark"arr[1]将包含"hey this is stack overflow"