Tapping and scrolling is great, but voice control is the next step. The rise of voice-based AI and voice-controlled gadgets like Amazon Echo and Google Home show clearly that controlling software by voice is a trend. Here you’ll find out how to integrate voice control into your Android app and benefit from it.

In 2015, Google released a new version of Android called Marshmallow. Marshmallow included the Google Voice Interaction API for developers. Google’s Voice Interaction API connects voice control to all apps on a device that support it. As a result, a user can make a request and it will be fulfilled with any app that’s able to do so. Then the user can control that app using voice commands.

Benefits of Voice Interaction

Controlling devices by voice is becoming more popular each year. It allows users to get information when they find it uncomfortable to use the screen. For example, I always use voice commands to find chords while playing the guitar and to find recipes while cooking, as do 23% of adults in US according to Northstar Research.

Companies that have already added Google Assistant actions to their apps, including TripAdvisor, Telegram, Walmart, and Flixster, have gained serious advantages over their competitors.

According to a study by Google, 55% of all teenagers and 41% of adults use voice commands more than once a day to find routes, make calls, and dictate texts. With time, the abilities of voice control become broader, and Google promises to add lots of new skills. Gartner predicts that by 2020, about 30% of searches will be done without a screen. ComScore gives an even more promising forecast, saying that 50% of searches will be done with voice by 2020.

These statistics show that it’s only a matter of time until it becomes common practice for people to use voice commands to find an address or play music. After you add voice control support to your app, it will appear in the list of apps that can perform a certain action. After a user chooses your app a few times while using voice control, Google will remember that preference and won’t ask again, opening your app by default for this type of request.

google assistant voice control
Google Assistant, like other voice control tools, is becoming more and more popular each day

Companies that have already added Google Assistant actions to their apps, including TripAdvisor, Telegram, Walmart, and Flixster, have gained serious advantages over their competitors.

Voice commands are of use in almost any kind of app: fitness, list-making, cooking, healthcare, ecommerce, and video streaming. For location-based apps, voice control will soon become a must, as asking for directions is the most popular reason to use voice commands.

Voice Interaction commands

When voice interactions appeared, there weren’t many commands available. Now the situation has changed, and the abilities of Google’s voice search are impressive.

Let’s explore the most useful commands that could be helpful for your app.

  • Get directions
  • Find nearby places
  • Find travel plans
  • Book a table
  • Track a package
  • Set reminders
  • Call or text someone
  • Start a video call
  • Play music or video

Of course, this isn’t the whole list of what a user can do with voice commands, but these are easy to imagine in a third-party application.

Soon, voice interactions will offer even more interesting functions. For example, according to Google, ordering food through voice commands is the most anticipated feature, and it may be available soon. This will make food ordering apps even more convenient!

Now let’s see how to integrate voice search in Android app.

Integrating voice interactions

There are four major steps you need to take to integrate voice interactions into your mobile app.

Step 1

First, you need to define Android versions and library versions you’ll support in your app. Mention them in your manifest to support voice commands.

android {
 compileSdkVersion 27
   buildToolsVersion '27.0.3'

 defaultConfig {
    minSdkVersion 23
       targetSdkVersion 27
 }
}

Step 2

Next, you need to set up an Intent Filter in the manifest to connect to Google Now and receive the voice intent from it. In this example, we ask our app to take a picture and launch a camera:

<intent-filter>
    <action android:name="android.media.action.STILL_IMAGE_CAMERA"/>>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.VOICE"/>
</intent-filter>

This is the code you need to activate search in your app:

<intent-filter>
    <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.VOICE"/>
</intent-filter>

Don’t forget to mention not only the voice category but also a default category.

You can create lots of such intent filters for anything you wish to support.

Step 3

Check your setup for voice interaction and use the handleQuery(query) method to process the search query.

String action = intent.getAction();
if (action.equals(Intent.ACTION_SEARCH)) {  
    String query = intent.getStringExtra(SearchManager.QUERY); 
        handleQuery(query); }

Step 4

Set up Google’s Voice Interaction API.

As one option can have many synonyms, add as many as you like within the option array. This will make successful responses more likely.

VoiceInteractor.PickOptionRequest.Option option1 =
        new VoiceInteractor.PickOptionRequest.Option(“Great Britain”, 1); 
    option.addSynonym(“United Kingdom”); 


VoiceInteractor.PickOptionRequest.Option option2 =
        new VoiceInteractor.PickOptionRequest.Option(“USA”, 1);

getActivity().getVoiceInteractor()
        .submitRequest(new PickOptionRequest("What is your favorite country?”, new Option[]{option1, option2}, null) {
            @Override
            public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) {
                if (finished && selections.length == 1) {
                    //Use the index of the options array to determine what was said
                    selections[0].getIndex();
            }
            @Override
            public void onCancel() {
                getActivity().finish();
            }
        });

How the Google Voice Interaction API works

Creating a conversation through the Voice Interaction API requires these four steps:

  • Retrieve the voice interactor
  • Submit a request to the voice interactor
  • Google handles the conversation
  • Handle the callback

Submitting a request is the most important part for a developer because everything else is handled by Google. Here’s a list of requests that developers can use:

PickOptionRequest (VoiceInteractor.Prompt prompt, Option[] options, Bundle extras) allows you to add any number of options. Each can contain different response strings that represent one value.

AbortVoiceRequest (VoiceInteractor.Prompt prompt, Bundle extras) is necessary if a voice interaction can’t proceed, as it will return the user to the app’s basic UI.

CommandRequest (String command, Bundle args) adds command strings that Google will use to retrieve relevant information, for example numbers or dates.

CompleteVoiceRequest (VoiceInteractor.Prompt prompt, Bundle extras) returns a user to the basic UI of the app if the voice interaction is successful.

ConfirmationRequest (VoiceInteractor.Prompt prompt, Bundle extras) is for situations when you need security confirmation from a user (e.g. while making a payment with a credit card).

Prompt (CharSequence[] voicePrompts, CharSequence visualPrompt) is the prompt that most requests need. The first string is the prompt and the second is what will be shown to your user.

Now you know how to give your app’s users the ability to control your app with voice. This can be a really useful feature and a serious advantage over your competitors. If you have any questions, be sure to write to Mobindustry. We can provide you technical assistance and advice on integrating voice interactions into your application.

Ecommerce development services

Are you planning to expand your business online? We will translate your ideas into intelligent and powerful ecommerce solutions.

Get a Free Consultation!
Request Callback

Request Callback

+