Just a quick example:
final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
void setup() {
}
void draw() {
}
void mousePressed() {
android.content.Intent intent = new android.content.Intent(android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// Specify the calling package to identify your application
intent.putExtra(android.speech.RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
// Display an hint to the user about what he should say.
intent.putExtra(android.speech.RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
// Given an hint to the recognizer about what the user is going to say
intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL,
android.speech.RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// Specify how many results you want to receive. The results will be sorted
// where the first result is the one with higher confidence.
intent.putExtra(android.speech.RecognizerIntent.EXTRA_MAX_RESULTS, 5);
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handle the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, android.content.Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
// The list of possible matches
ArrayList matches = data.getStringArrayListExtra(android.speech.RecognizerIntent.EXTRA_RESULTS);
if (matches.size() > 0) {
println((String)(matches.get(0)));
}
}
}