There is one available RecognizerIntent in android.
Step 1: Starting RecognizerIntent First we need to create a RecognizerIntent by setting necessary flags such as ACTION_RECOGNIZE_SPEECH – Simply takes user’s speech input and returns it to same activity LANGUAGE_MODEL_FREE_FORM – Considers input in free form English EXTRA_PROMPT – Text prompt to show to the user when asking them to speak
Step 2: Receiving the speech response Once your speech input is done,this intent return all the possible result in OnActivityResult.As usual we can consider the first result as most accurate and take possible action whatever we need to do.
Please refer following code snippet and link for complete reference.
LINK : http://www.androidhive.info/2014/07/android-speech-to-text-tutorial/
/**
* Showing google speech input dialog
* */
private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}
/**
* Receiving speech input
* */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQ_CODE_SPEECH_INPUT: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
txtSpeechInput.setText(result.get(0));
}
break;
}
}
}