Reputation: 9
I want to make a simple game which has a function of PICK, LEFT, Right and stop.
My problem is I want to make those functions of the game into a voice recognition using the speech to text function of android. I'm using eclipse as my IDE, I want to know how to integrate it with an application.
Hope you can give me a sample, it'll be a great help.
Upvotes: 0
Views: 444
Reputation: 12169
Well you need two things.
Run the speech recognizer in the background so there is no annoying dialog interfering with the game
Recognize your target words reliably
For #1. You'll need SpeechRecognizer and a loop to run it, such as the one that uses this, or I guess you could use the dialog version. Either way start off using this abstract class to give you a head start.
For #2, you have to do some testing. Download the Android Sensor Playground app to see if the recognizer can reliably recognize your words. If that is true, just use a simple Sting<Set>
to match any recognition results. (or you could use this handy class) If the recognizer is giving you trouble on certain words, then you need some stemming or phonetic matching. See this class.
Upvotes: 0
Reputation: 3453
Intent i = new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say the command!");
startActivityForResult(i, 10);
Then add on activity result.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 10 && resultCode == RESULT_OK) {
ArrayList<String> s = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
//Do whatever you want with the data here.
super.onActivityResult(requestCode, resultCode, data);
}
Upvotes: 1