Voice Search use in Your Android Application

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;
}
}
}

Page Views (174)

853 Total Views 2 Views Today
Share Love & Support:

About Pratik Butani

Pratik Butani is Enthusiastic Android Application Developer, Speaker at Google Developer Group – Rajkot, All time Learner of new things, Googler, Eager to Help IT Peoples. He also like to TEACH Android to New Learner and Share his knowledge to them. He is currently working as a Senior Android Developer at Soham ERP Solutions Pvt. Ltd. – Ahmedabad. He is working with Android Development since 2013 and now Flutter is on going.

Comment Your Suggestion or Appreciation:

Loading Facebook Comments ...

Leave a Reply

Your email address will not be published. Required fields are marked *