Google Voice Search or Search by Voice is a Google product that allows users to use Google Search by speaking on a mobile phone or computer, i.e. have the device search for data upon entering information on what to search into the device by speaking.
Here i have created one demo to get input without typing and that is done by Google Voice Search Feature.
Google Voice Search in all Devices |
Let's see how to get input from user without typing:
Call the following code while click on button or as you want:
/* Call Activity for Mic */
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(intent, 1);
} catch (ActivityNotFoundException a) {
Toast t = Toast.makeText(context, "Oops! Your device doesn't support Speech to Text",Toast.LENGTH_SHORT);
t.show();
}
Now get the result using onActivityResult():
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 1: {
if (resultCode == Activity.RESULT_OK && null != data) {
searchView.setIconified(false);
ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
searchView.setQuery(text.get(0), true);
searchView.requestFocus(SearchView.FOCUS_RIGHT);
}
break;
}
}
}
No comments:
Post a Comment