6 December, 2021

How to Implement the Voice Recognition Functionality in Android Devices?

Mobile devices that come with facilities like multi-touch, camera, internet access and audio for speech recognition are becoming immensely popular these days. Among the various functionalities, speech recognition (or voice recognition) makes it suitable for deploying applications using NUI technologies like multi-touch, speech recognition, spatial gestures and so forth. In simple this speech recognition functionality is specifically designed to duplicate and respond to the human voice.

Speech technology allows hands free use of computers and supports access to computing capabilities away from desk and over the telephone. Speech recognition for application Voice SMS is done on Google server.

This post illustrates one of the finest methods to implement the voice recognition functionality in android devices. Follow the below steps to accomplish this functionality on your android devices.

Steps to Follow:

Prior to entering into developing your voice recognition module, first check whether your mobile phone supports voice recognition. In order to check this, follow the below steps.

PackageManager pm = getPackageManager();
List activities = pm.queryIntentActivities(new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() == 0) {
mbtSpeak.setEnabled(false);
mbtSpeak.setText("Voice recognizer is not available in your device")
Toast.makeText(this, "Voice recognizer is not available in your device",
Toast.LENGTH_SHORT).show();
}

 

The Implementation Process

Once you’ve checked whether the module is supported on your phone, carry on with the below steps to implement it successfully.

The heart of Speech to text in Android API is package android.speech and specially the class android.speech.RecognizerIntent.

Intent intent = newIntent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

Voice recognition feature can be achieved by RecognizerIntent. Create an Intent of type RecognizerIntent and pass the extra parameters and start activity for the result. It basically starts the recognizer prompt customized by your extra parameters. Internally, voice recognition communicates with the server and gets the results. So you must provide the internet access permission for the application.

Below described are the functions which are called above:

Call the RecognizerIntent – Your application calls the Voice Recognition Intent that records the voice.

ACTION_RECOGNIZE_SPEECH – Starts an activity that will prompt the user for speech and send it through a speech recognizer.

EXTRA_LANGUAGE_MODEL – Informs the recognizer that which speech model should be preferred when performing ACTION_RECOGNIZE_SPEECH. It is adapted to input messages in English.

Only certain languages and locales are supported by the speech services. For example, English is widely supported, as well as some other languages. However, your application should check for specific language support programmatically prior to use.

Android Jelly Bean(API level 16) doesn’t require internet connection to perform voice recognition. Once the voice recognition is done, recognizer returns value in on ActivityResult() method parameters.

Permission in Manifest File

INTERNET permission has been provided to the application because of the voice recognizer’s need to send the query to the server and get the result.

uses-permission android:name=”android.permission.INTERNET”

Voice SMS Application

A speech-to-text system can also improve system accessibility by providing data entry options for blind, deaf, or physically challenged users. Voice SMS is an application developed in this work that allows a user to record and convert spoken messages into SMS text message. User can send messages to the entered phone number.

You may have heard about the “Google Now project” where you give the voice command and Android fetches result for you. It recognizes your voice and converts it into the text or takes the appropriate action.

Google has accumulated a very large database of words derived from the daily entries in the Google search engines as well as the digitalization of more than 10 million books in Google Book Search project. The database contains more than 230 billion words. If we use this kind of speech recognizer, it is very likely that our voice is stored on Google’s servers. This fact provides continuous increase of data used for training, thus improving accuracy of the system.

Deploy and Run the Application

Deploy and run the application in Android devices running on Android 2.1 or higher version. Android emulator does not support Speech recognition and so we need an android device for testing the application which should have good internet connectivity.

Offline Voice in Jellybean

Previously, when you pressed the voice icon and spoke a command or query, Android had to digitize your voice, upload it to the cloud, process the waveform, turn it into text, and send the text back down to your phone. Now the phones are powerful enough that this can be built into the device, with no extra network I/O needed. As you can imagine this results in much faster voice recognition than previous versions.

The Future

The objective of the future is development of models and databases for multiple languages which could create a foundation for everyday use of this technology worldwide. The main goal of this kind of application is to allow sending of text messages based on uttered voice messages. Testing has shown simplicity of use and high accuracy of data processing. Results of recognition give user option to select the most accurate result.

Our further plan is about implementing the model of speech recognition for different languages. Will be back with a similar kind of informative post very soon. Please do share your comments, ideas and suggestions on this post below!

Have an App Idea? Let’s Talk

Share

Aruna, Mobile Application Developer with 1.5 years experience in Android Application Development, WebServices,Google Maps and Chart API,In-App Purchase and So on.Especially she serviced global level clients with high quality and value those consumers.

6 Comments

  1. Rachele Reply

    Voice to Text is the new trend, but this is truly amazing to get a text over voice in an sms application.Thanks for the code part, please add some gif screens if possible.

  2. Sharnendra Reply

    please is it possible to design a code such that if the voice input is “hello” then reply is always “hi” and it does not require internet

    1. Masi Reply

      Artificial Intelligence along with text to speech technologies can achieve voice replies from chatbots. However, without a working Internet connection it will not function. The chatbot needs a secure connection to contact the server and synthesize the information to retrieve a suitable response to the user query.

    2. Kumar Shubham Reply

      Sure it is – Results of recognition are received via a callback. Within the callback, check if the received string is exactly equal to “Hello”. If it is, start a MediaPlayer object and play back an audio file that says “hi”.

  3. Jose Reply

    Hi, I need to start Voice recognition on push button event. Actually Im doing it and its works, but in a Activity called by other Activity.. now I have a service running and when I press X Button, it must start the Voice Service (I think it must be a service too, because a Service cannot instance o start a Activity)
    PLEASE HEEEELP !!!

Leave a Reply

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