Robert Oschler
Robert Oschler

Reputation: 14375

Can Android voice recognizer return more than one match?

When doing speech recognition using Google's server's via Chrome's HTML 5 speech input support, you get back roughly 6 results each time that are the 6 possible interpretations of the user's voice audio. When I do the same operation in my Android app, I only seem to get back one. Is this just the way it is or is there a setting that will cause the Android recognizer intent to return more than one utterance?

Relevant code samples:

/**
 * Fire an intent to start the voice recognition activity.
 */
private void startVoiceRecognitionActivity()
{
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech reco demo...");
    startActivityForResult(intent, REQUEST_CODE);
}

/**
 * Handle the results from the voice recognition activity.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
    {
        // Set the current global speech results to this latest session's.
        ArrayList<String> matches = data.getStringArrayListExtra(
                RecognizerIntent.EXTRA_RESULTS);

        AndroidApplication andApp = AndroidApplication.getInstance();

        andApp.speechRecoResults.setContents(matches);
    }

    super.onActivityResult(requestCode, resultCode, data);
} // onActivityResult()

UPDATE: I added the following line of code to startVoiceRecognitionActivity() as per |Z|Shadow|Z| right before the startActivityForResult() call and I get multiple utterances now:

intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);

-- roschler

Upvotes: 2

Views: 1429

Answers (1)

IZI_Shadow_IZI
IZI_Shadow_IZI

Reputation: 1931

Yes it can return multiple utterances I have a few implementations that do such. Could you post the code you are using so we could help you out better?

Answer to comment:

Yes and I can set it to return however many the server picks up...I usually just set it to 5. Check my previous post which includes my code of one implementation. Voice Recognition as a background service This one disables Google's dialog box that pops up when you record. THis line gets the amount of results to return: intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5)

Upvotes: 2

Related Questions