ايمان محمد
ايمان محمد

Reputation: 43

How to get only one result back when doing voice to text?

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. I only want one result,, how would i do that?

here is my code:

    package com.emanrox.tutorialbasics12;

    import java.util.ArrayList;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.speech.RecognizerIntent;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ListView;

    public class Voice extends Activity implements OnClickListener {

ListView lv;
static final int check = 1111;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.voice);
    lv = (ListView)findViewById(R.id.lvVoiceReturn);
    Button b = (Button)findViewById(R.id.bVoice);
    b.setOnClickListener(this);

}

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,                   RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak up son!");
startActivityForResult(i, check);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
if (requestCode == check && resultCode == RESULT_OK){
    ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,results));


}



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

}

Upvotes: 1

Views: 821

Answers (1)

Kaarel
Kaarel

Reputation: 10672

Maybe set the MAX_RESULTS extra to 1.

I'm not sure though what is the relationship between your code and the Chrome HTML 5 speech input. And why can't you just discard the additional results? Sometimes it's easier for the service to deliver multiple results and then the client has to post-process them...

Upvotes: 1

Related Questions