0

I am trying to develop an android application with speech recognition. Please have a look at the below code.

 @Override
 public void onPartialResults(Bundle arg0) {
      Log.i(LOG_TAG, "onPartialResults");
      ArrayList<String> matches = arg0.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
      float[] scores = arg0.getFloatArray(SpeechRecognizer.CONFIDENCE_SCORES);
      receiveWhatWasHeard(matches, scores);

      //Get result with highest score
 }

My problem here is to get the result with "Highest Confidence Score". How can I do that?

Vivek Singh
  • 2,047
  • 11
  • 24
PeakGen
  • 21,894
  • 86
  • 261
  • 463

1 Answers1

3

First element has the highest confidence score according to specification, so you can just take the first element of an array:

String bestResult = arg0.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).get(0);

You do not need to retrieve confidence scores if you do not intend to use them.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87