Get a phrase from speech recognizer similar to result returned by Google Now

336 views Asked by At

Im currently building a feature of my app that should allow the user to say a phrase which will then be compared with a phrase said by another user to determine if they are equal. I am getting back results from the Speech Recognizer Intent as follows.

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
 {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {

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

When I tried it by saying "Testing 123" I got back an array populated with "Testing 123, Testing one two three, Piscon 123"

Is there a way I can only extract the most accurate phrase from the result such as just "Testing 123" ? When I do a search with Google Now only the most accurate representation of what I said is returned so I'm wondering if this functionality can be achieved.

I tried "How high can you jump" and got this result. Is there a way to somewhat determine the start of the next sentence so I can extract the most positive result?

enter image description here

1

There are 1 answers

0
David M On

If you'd like to get just the most accurate, you'll want to also grab EXTRA_CONFIDENCE_SCORES. You'll want to find the highest confidence score and the corresponding String value.From the documentation

public static final String EXTRA_RESULTS

Added in API level 3 An ArrayList of the recognition results when performing ACTION_RECOGNIZE_SPEECH. Generally this list should be ordered in descending order of speech recognizer confidence. (See EXTRA_CONFIDENCE_SCORES). Returned in the results; not to be specified in the recognition request. Only present when RESULT_OK is returned in an activity result. In a PendingIntent, the lack of this extra indicates failure.

And confidence scores:

public static final String EXTRA_CONFIDENCE_SCORES

Added in API level 14 A float array of confidence scores of the recognition results when performing ACTION_RECOGNIZE_SPEECH. The array should be the same size as the ArrayList returned in EXTRA_RESULTS, and should contain values ranging from 0.0 to 1.0, or -1 to represent an unavailable confidence score.

Confidence values close to 1.0 indicate high confidence (the speech recognizer is confident that the recognition result is correct), while values close to 0.0 indicate low confidence.

Returned in the results; not to be specified in the recognition request. This extra is optional and might not be provided. Only present when RESULT_OK is returned in an activity result.