Voice Search
Intent intent = new Intent(android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL, android.speech.RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(android.speech.RecognizerIntent.EXTRA_PROMPT, "Voice");
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) { Toast.makeText(getApplicationContext(), "Activity not found", Toast.LENGTH_SHORT).show();
} } @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 result = data .getStringArrayListExtra(android.speech.RecognizerIntent.EXTRA_RESULTS);
edittext1.setText(result.get(0));
} break; } }
Comments