Android Java

Android; How to implement voice recognition, a nice easy tutorial…

I’ve been searching for a simple tutorial on using voice recognition in Android but haven’t had much luck. The Google official documentation provide an example of the activity, but don’t speculate anything more than that, so you’re kind of on your own a little.

Luckily I’ve gone through some of that pain, and should make this easy for you, post up a comment below if you think I can improve this.

I’d suggest that you create a blank project for this, get the basics, then think about merging VR into your existing applications. I’d also suggest that you copy the code below exactly as it appears, once you have that working you can begin to tweak it.

With your blank project setup, you should have an AndroidManifest file like the following

&lt;?xml version="1.0" encoding="utf-8"?&gt;<br>
&lt;manifest xmlns:android=""<br>
    &lt;application android:label="VoiceRecognitionDemo" android:icon="@drawable/icon"<br>
        &lt;activity android:name=".VoiceRecognitionDemo"<br>
                &lt;action android:name="android.intent.action.MAIN" /&gt;<br>
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;<br>

And have the following in res/layout/voice_recog.xml :

&lt;?xml version="1.0" encoding="utf-8"?&gt;<br>
&lt;LinearLayout xmlns:android=""<br>
<p>    &lt;TextView<br>
        android:text="Click the button and start speaking" /&gt;</p>
<p>    &lt;Button android:id="@+id/speakButton"<br>
        android:text="Click Me!" /&gt;</p>
<p>    &lt;ListView android:id="@+id/list"<br>
        android:layout_weight="1" /&gt;</p>
<p> &lt;/LinearLayout&gt;<br>

And finally, this in your res/layout/main.xml :

&lt;?xml version="1.0" encoding="utf-8"?&gt;<br>
&lt;LinearLayout xmlns:android=""<br>
    android:text="VoiceRecognition Demo!"<br>

So thats your layout and configuration sorted. It will provide us with a button to start the voice recognition, and a list to present any words which the voice recognition service thought it heard. Lets now step through the actual activity and see how this works.

You should copy this into your activity :

package com.jameselsey;</p>
import android.os.Bundle;<br>
import android.content.Intent;<br>
import android.speech.RecognizerIntent;<br>
import android.view.View;<br>
import android.widget.ArrayAdapter;<br>
import android.widget.Button;<br>
import android.widget.ListView;<br>
import java.util.ArrayList;<br>
import java.util.List;</p>
 * A very simple application to handle Voice Recognition intents<br>
 * and display the results<br>
public class VoiceRecognitionDemo extends Activity<br>
<p>    private static final int REQUEST_CODE = 1234;<br>
    private ListView wordsList;</p>
<p>    /**<br>
     * Called with the activity is first created.<br>
    public void onCreate(Bundle savedInstanceState)<br>
<p>        Button speakButton = (Button) findViewById(;</p>
<p>        wordsList = (ListView) findViewById(;</p>
<p>        // Disable button if no recognition service is present<br>
        PackageManager pm = getPackageManager();<br>
        List&lt;ResolveInfo&gt; activities = pm.queryIntentActivities(<br>
                new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);<br>
        if (activities.size() == 0)<br>
            speakButton.setText("Recognizer not present");<br>
<p>    /**<br>
     * Handle the action of the button being clicked<br>
    public void speakButtonClicked(View v)<br>
<p>    /**<br>
     * Fire an intent to start the voice recognition activity.<br>
    private void startVoiceRecognitionActivity()<br>
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);<br>
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");<br>
        startActivityForResult(intent, REQUEST_CODE);<br>
<p>    /**<br>
     * Handle the results from the voice recognition activity.<br>
    protected void onActivityResult(int requestCode, int resultCode, Intent data)<br>
        if (requestCode == REQUEST_CODE &amp;&amp; resultCode == RESULT_OK)<br>
            // Populate the wordsList with the String values the recognition engine thought it heard<br>
            ArrayList&lt;String&gt; matches = data.getStringArrayListExtra(<br>
            wordsList.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,<br>
        super.onActivityResult(requestCode, resultCode, data);<br>

Breakdown of what the activity does :

Declares a request code, this is basically a checksum that we use to confirm the response when we call out to the voice recognition engine, this value could be anything you want. We also declare a ListView which will hold any words the recognition engine thought it heard.

The onCreate method does the usual initialisation when the activity is first created. This method also queries the packageManager to check if there are any packages installed that can handle intents for ACTION_RECOGNIZE_SPEECH. The reason we do this is to check we have a package installed that can do the translation, and if not we will disable the button.

The speakButtonClicked is bound to the button, so this method is invoked when the button is clicked. I wrote another tutorial on button binding so have a look at that if you don’t understand this method.

The startVoiceRecognitionActivity invokes an activity that can handle the voice recognition, setting the language mode to free form (as opposed to web form)

The onActivityResult is the callback from the above invocation, it first checks to see that the request code matches the one that was passed in, and ensures that the result is OK and not an error.

Next, the results are pulled out of the intent and set into the ListView to be displayed on the screen.

Notes on debugging :

You won’t have a great deal of luck running this on the emulator, there may be ways of using a PC microphone to direct audio input into the emulator, but that doesn’t sound like a trivial task. Your best bet is to generate the APK and transfer it over to your device (I’m running an Orange San Francisco / ZTE Blade).

If you experience any crashing errors (I did), then connect your device via USB, enable debugging, and then run the following command from a console window

&lt;android-home&gt;/platform-tools/adb -d logcat<br>

What this does, is invoke the android device bridge, the -d switch specifies to run this against the physical device, and the logcat tells the ADB to print out any device logging to the console.

This means anything you do on the device will be logged into your console window, it helped me find a few null pointer issues.

That’s pretty much it, its quite a simple activity. Have a play with it and if you have any comments please let me know. You may have mixed results with what the recognition thinks you have said, I’ve had some odd surprises, let me know!

Happy coding!

Further Reading :

  1. ADB Commands
  2. Official documentation

Was this post helpful? Feel free to donate some coin.
BTC: 16ZwowSmkFpcephGBrQ3fcWjqqF7wc5z2P
ETH: 0xFbc44763E9370b33d42381E3af8ee82F2BEE31B3
BAT: 0xFbc44763E9370b33d42381E3af8ee82F2BEE31B3
XRP: rKqSReUCavKBbTUe6vEaeSLJK3ehjP4tgK
Donations help with hosting costs and gear for more content

98 replies on “Android; How to implement voice recognition, a nice easy tutorial…”

Hi James! This is a brilliant tutorial, at least now I understand the code for speech recognition with android. However it shows “recognizer not present” when I run it. What can be the problem? I have a C#speech recognition’s application that work properly on the same machine.
Is there a setting that I should make in order to enable the recognizer for android?
Thank you

Hi Patrick, glad I’ve helped.

When you say you have C# speech recognition, what do you mean by that? Something installed on your local PC? Are you running this on the emulator or on a device?


Thanks for the quick response.
I meant that I am able to use the Windows 7 Speech recogniser via a C# application. I was hoping that it will be the case with an android application using the emulator. But I just read that the SDK does not include the speech recognition and that it should work on a device, I don’t have a device yet.
It there any thing that I can do to attach the speech recogniser to my SDK so that I can use it with my emulator?

Hi James,
Thanks for the very good tutorial. I don’t know if its possible to do without getting into unpublished methods within the RecognizerIntent, but I’m trying to run the VR in a service that is interval controlled, and most important DOES NOT SHOW A PROMPT. Do you have any suggestions or can you steer me to a resource that might help?


Hi Dave,

Thank you for the kind words, glad I’ve helped. So you want to start off VR from a service that is interval controlled, can I assume that by interval controlled you mean once every X number of seconds for example?

Any reason why you specifically need a service for this and why you can’t stick with a basic activity? In regards to not showing a prompt, I’m not sure we have much control over that since its part of the droid SDK, but there may be a way of masking that out, I’ll do some digging.


I guess I can use an Audio Sensor (do you know of a good tutorial, I got errors on Frank Ableson’s tutorial, still can’t get it to work)

If there is no way to override the RecognizerIntent class I will have to write my own using the MediaRecorder, ugh.

I Need to run as a persistent service for his app, it never completely stops and yes, I will be controlling the interval the VR runs, and stops.

Interesting, well heres what I think..

Create a service to do the VR, then have your activity start/stop this based on a time interval. Inside the service you will need to fire off intents to the VR action. I’m not sure how you’ll keep the VR open for extended periods of time (since if it doesn’t hear anything after x number of seconds it will fail).

To cover the default prompt you may have to show a view on top of it to mask it out (i.e., show a splash screen over it).

I’d have to dabble in a bit more code to give any better advice :)

Hey, I tried the code on a recent samsung powered with android but it says the same “recognizer not present”. How did you manage to get it working? Is there specific settings?

Hi Patrick, this means that your handset doesn’t have an voice recognition engines. You can go onto the market place and download google Voice if you don’t already have it.

My app makes use of VR engines, but it doesn’t provide one itself

Hope this helps

Hi Simphiwe,

This means that you don’t have any voice recognition engines on your handset, go onto the marketplace and download Google Voice.

My app makes use of VR engines, but it doesn’t provide one itself.

Hope this helps

thank you for your tutorial. i am trying to run this code using my own database. i prepared my language and acoustic models for the arabic language but I do not know how to connect my database with this code.
my application is samall it includes only 10 words(i say the number in arabic and it writes it down).
the source i am using for the training is a jar file and it saves my results in zip files.

Hi Amal,

Interesting app you have there!

What behaviour are you experiencing? I think you might have problems using Arabic, this is what the Google website says :

Google’s servers currently support English, Mandarin Chinese, and Japanese. The web search model is available in all three languages, while free-form has primarily been optimized for English. As we work hard to support more models in more languages, and to improve the accuracy of the speech recognition technology we use in our products, Android developers who integrate speech capabilities directly into their applications can reap the benefits as well.

So I think that possibly Arabic is not support yet.

Your tutorial was wonderful and worked like a charm, I have a question about VR. Is it possible to input 1 sound and receive another? For example : I input the phrase “I want to go to sleep” and the VR exports the phrase “then go lay down” or “it’s not your bedtime yet”. So i want to input one value/word and have the VR export another desired value. Is that possible? and if so can you point me in the right direction?

You can absolutely do that! However there will be some difficulties along the way. How should the app know how to respond? Will you have a database of phrases, whereby if one is detected, it will know the mapping to the response? Or are you planning some form of Artificial Intelligence to do this?

Also, the VR can be a little sketchy depending on accents and so forth, I tend to mumble a little bit and it often has trouble detecting what I’m saying.

Interesting idea you have though, I’d like to hear how it goes :)

Thanks for the speedy response! To answer your questions “How should the app know how to respond? Will you have a database of phrases, whereby if one is detected, it will know the mapping to the response? Or are you planning some form of Artificial Intelligence to do this?” … I don’t know yet. I was thinking of adding a database of catch words, whereas if input is “A” export is “Z”, but I don’t know how to set the Method to do that yet. I mean if i could just learn how to set the first method, i could figure the rest out. Or if i the format for manipulating the database was present, i would at least have a starting point. Any help?
Thanks in advance.

Sounds a bit fiddly, you could store phrases in a database, then when one is spoken you can obtain all the words and see how many of those match the set phrases you have, for example if 8 out of the 10 words match, you’d be pretty confident. Thats just one way of doing it.

The technical side should be fairly easy, just reading/writing to a SQLite instance, the tricky part is working out the business logic of how you want it to work.

Personally (without knowing any more about what your app does) I would store set phrases such as “Hello my name is ?” and then when it hears “Hello, my name is James”, it would recognise the words “Hello”, “my”, “name”, “is”, “James” and map them to a set response. The name James would be detected as a variable and used in the response “Nice to meet you James”.

Good luck!

Yeah, create yourself a database, a table, and populate it with some dummy data. Please checkout the SQLite tutorial I did, it covers pretty much all of the aforementioned.

You can use an online database, or a local SQLite db, or even sync the two, its up to you and depends if you need offline modes.

Hi James .
In my case i have just copied the existing VoiceRecognitionDemo code you have given here and i am running the code through device but after clicking on button i am getting connect error ..
just to mention Google voice search is installed on phone and running perfectly
Please help

Connect error? Sounds like you don’t have internet connection, which you would need for the VR to work.

Couple of things, check your internet connectivity, make sure manifest has internet permissions.

If that still doesn’t work, put your logs into and give me a link! :)

yeah yes it worked that time only..i refered some blog where it was mentioned that we need to have nternet for google voice search as it has to connect google data server..
anyways thanks for quick reply

That is true, everytime you speak into the app, it collects that audio data and sends it off to Google for them to do their “crunching” and then replies with the text, so you must have internet connectivity.

Happy coding :)

Hi James, I was just wondering how long does it take to recognize a word if it has to go to google servers 1st. how many bytes get send and received per word? Is there any way you can use this class without internet access?

Hi Bennie,

It depends really, it depends on how many words you are processing, for example if you are quoting 2 pages from a book it will take a bit longer!

Also depends on your internet connection, if you have really slow connection the data transfer will obviously take longer.

No idea about how many bytes, haven’t been concerned with that low level stuff.

If you want to use the Google VR engine then you’ll need internet access, I don’t believe there is a way around that. However there may be other 3rd party VR engines that work in offline mode, I’m not too sure.

Hope this helps

Hey James,

Thanks for the great tutorial!
Unfortunately I get a “recognizer not present” message on my phone. (Also ZTE Blade)

This is probably due to the fact that for some reason Google Voice is not supported in my country for some reason. (Israel)

I wonder if I can somehow get another speech recognizer to work, maybe you know about another application?

I’m a total Android noob btw.


hi james,i am from india,am doing my academic project in one of MNC company.I want to impliment biometric application in android mobile phones.Through voice recognition my mobile should be unlocked, it shld be unlocked for my own can u suggest code releted to my project.

Hey! I would like to know if there is a way of not using the speech server (Voice search).
The Voice dialler apparently use an engine which is on the phone. I have seen a couple of app that do too.

Hello, brilliant tutorial! I get one error though :( “Can’t dispatch DDM chunk 52454151: no handler defined” I have tried everything to fix this! Any chance you can send me the .apk of yours so I can see what is different? Thank you in advance!

Hi James,brilliant tutorial. I’m new to speech recognition and Android, and would like to know how is a database for a speech app created ( i.e. if you are creating your own db, say of 10 words only) and how is it connected to the app?

Hi James, brilliant tutorial indeed. I am new to Android and speech recognition and would like to know how is a database of a speech recognition app (i.e. an app working without google search or offline) built and how are the two(app & db) connected. do have any idea? please help

Hi Chepe, I’m not too sure since it is not something I’ve investigate too much (offline TTS that is) however there is more than likely APIs out there which you can include in your app. App/DB interconnectivity will probably be via SQLite if local, or some kind of web service call if you have a centralised base on the web.
Hope this helps :)

Philipino…We want to know what are the processes in putting natural voices in android so that we can make text-to-speech in philipino.. we are trying to use Syllabification Algorithm..thanks..

Hi James, Great tutorial :).

Can I use this engine to recognize sounds of an object rather then words (for example hearing a car or hearing a keyboard pressed)?
I want to identify the objects by the sound

Or I have to develop my own engine that do so?

Hi James ,

Nice Tutorial …

Wondering if you can upload somewhere the the “apk” so that i can test it on my device before playing with the codes …

Thanks , will be of great help if u can do so asap


why is it that if i say good morning even then it shows me a list good morning strings added with boarding govin body on listed..
is there a wayh to filter out and list out the exact words spoken out..
pleas reply for the same..thank u..

Hi james,

thax for your tutorial ,its very useful for beginnig speech recognition.I ask you this:when I debug it activities (list parameter) size null ,so run if clause directly.This is a simple mistake about hardware or something ,I think.What about you?

hi james..
how can i add speech recognizer in my emulator ?????? i have no android phone……through emulator i am trying to download voice recognizer bt failed … i also used update sdk 3.2 bt failed ………plz help me……….i need a detail help.

Hi Auvy, I’m not quite sure, as you would need some way of sending voice input into the emulator. There must be a way via the ADB, but I’m not entirely sure, you’ll have to Google for it. If all else fails, try asking on, its a great site for quick and detailed answers. Good luck!

Hi James,

Thanks for the tutorial. I have it almost working.

First it wasn’t working at all, because I had no speech recognizer. So I installed voice search and now the button is visible. When I click on the button it starts. But then once I say anything the program crashes. I get the following error:

“The application Voice Search (process has stopped unexpectedly. Please try again. – Force close.

Any ideas as to what I should do?

Kind Regards


Fixed it! This will answer the question for allot of people here who want to know how to get a “voice search” speech recognizer other than google voice.

Just go to Android market and download an app called “Jeannie”. When you start the app it will say you need to download a speech recognizer. It gives you an option to install voice search for android 1.5 or android 2.1. Then your app works perfectly!

Thanks again James.

I am get the recorded audio.
Is there any one could help me for to change the recorded voice in to mechanical voice ,i.e robot, cat.

Thanks in advance

hi james thanks for the tutorial…I am doing a project on voice recognition i am new to android.My project is as follows as we say send msg to [recipient][message] it should send to the particular person i have mentioned in the same way to call, to listen to music, to view map,and to show directions through map can u please help me out while coding

Hi Vijay,

Interesting project you have going there, is it for university or just for fun?

I’m not quite sure what you are trying to do, but it sounds as if you want to speak something and have it sent to someone. I’d suggest you have a read about voice recognition on android and cook up a few quick little apps to play around. If you get stuck with anything specific please let me know!

hmmmm thank u so much james for ur quick response…i am just getting trained in android in a small institute…and just want to do my first project…i will send u the abstract of the project so that u can better understand…..

Abstract for voice applications:
Send text messages

Say “send text to [recipient] [message]*”

e.g. “send text to Vijay “I am busy call u around 9”

Listen to music

Say “listen to [artist/song/album]”

e.g. “listen to the kolaveri”

Call contacts

Say “call [contact name] [phone type]*”

e.g. “call Vijay home”

Send email

Say “send email to [recipient] [subject]* [body]*”

e.g. “send email to Vijay How’s life in India treating you? The weather’s beautiful here!”

View a map
Say “map of [address/city]”

e.g. “map of New Delhi”

Go to websites

Say “go to [website]

e.g. “go to Wikipedia”

Write a note(Remainder)

Say “note to self [message]”

e.g. “note to self grocery list banana milk eggs pizza”

Search Google

Say “[your query]”

e.g. “pictures of the golden gate bridge at sunset”

OK so your app needs to sit there listening, then when it hears one of a preset list of commands, determine which one it is, then action it accordingly, conceptually quite easy.

Best thing I can suggest, is to break this down and experiment with some code. Create a basic app that will listen for commands, then repeat them back to you. Next, create an app that will action the commands when you click a button. Finally, scrap both of them and start fresh, using the knowledge you have, and tie them both up together.

Voice recognition is quite nice, but it can sometimes struggle with regional accents, so bear that in mind when developing, speak like an American :)

Thanks for your help earlier. If I have recognizer close and open again for next command, why do i get 1st results, and not 2nd? Do I have to close recognizer to send 2nd results to be stored in results? or?

Thank you in advance.

Hi James, I found your interesting tutorial when searching VR Android. I’m working on a project to bring VR to our learning platform. You know many young children are shy or can’t speak correctly even when they are 3 or 4?
The idea is to design a game that can recognize the input from a child player. For example the child can say “bring me an apple”, and game character will do accordingly. Do you think it’s realistic to use the current Android open source? Do you provide programming service? Thanks

Sure, anything is possible if you invest enough effort. Really depends how clear the child speaks, if they mumble a little bit I’d imagine the VR engine may struggle to detect what they’re saying

hello, i want to make a project speech recognition on andriod.. please sugess me from where i have to start…. and what type of software i need…

Hi James. Thanks for this. I understand the difference between ACTION_WEB_SEARCH and ACTION_RECOGNIZE_SPEECH as explained in Android dev docs and your example here..

But I am wondering if you or anyone else has practical experience with getting qualitative differences in results using these 2 different language models. I’d like to use the voice recognition in a tutorial that uses voice to select from a finite set of button labels.

Hello James, I got interested with your tutorial and tried implemented your given codes. However, i got the same problem “Recognizer not present”. I downloaded this file but don’t know how to integrate it with the application. Please help. I’v been stacked with this. I have combed the various forums over the net but can’t find the answer. I am using android 4.0.3. Also, will this googlevoice run in an emulator? thanks…

Hello James, I got interested with your tutorial and tried implemented your given codes. However, i got the same problem “Recognizer not present”. I downloaded this file but don’t know how to integrate it with the application. Please help. I’v been stucked with this. I have already combed various forums over the net but can’t find the answer. I am using android 4.0.3. Also, will this googlevoice run in an emulator? thanks…

Hi James,

Great tutorial. Simple to follow and great to get started with.

I followed and it works fine but I’m working on an android project that requires to convert a mp3 record to text. Any idea how can I do this?


Hi Dude,
I am trying to create a service which should always listen for any voice command(if not screen locked), I need your help in that…. Pls reply me as soon as possible…!

A service class would probably handle that well, perhaps coupled with a widget would be nice :)

I’m magicFox.
Have you know that Google service Voice recognition SDK or the jar file? I want to use the plug in the the application.If you have some idear,can you give me a email?

Thank you very much!

Hey james i currently working on a app that should detect a Beep and trigger an event in the database . Can you help me the code and sample code . I m thinking of using it as a service which will run in background and keeps waiting for the beep to occur and it will store the current time in the database . Can you please help out with this .I am new to android . My email-id .

Thank you

hi james,
no doubt it is a great tutorial.. but i like to know can we will do voice recognition without internet….
i will be very thankful to youy if you will provide me the code…for it…plz revert me…

Hi James, I have a question. Do you know of a way to make the speech recognition listen for an extended period of time?


It seems to be working but I got no results in the ListView. So I tried Google Search and it works fine.
Please let me know what could be the problem.

thanks for your tutorial!!
im trying to build voice based media player for visually impaired people, could you please help by integrating the voice code with media player.

hey james… thanks alot for a great tutorial…
But I am trying to do some thing different by the help of this tutorial……
I am doing voice recognition but without internet or you say offline. please help me in doing this. As i have done wioth this code it takes help of google api. So please help me in this that I will search or call my words but without the help of google api…. if possible plz help me in doing this

Leave a Reply

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