Android comes with an inbuilt feature speech to text through which you can provide speech input to your app. With this you can add some of the cool features to your app like adding voice navigation(Helpful when you are targeting disabled people), filling a form with voice input etc.,

In the background how voice input works is, the speech input will be streamed to a server, on the server voice will be converted to text and finally text will be sent back to our app.

If you want to do the other way i.e converting text to speech, follow my previous tutorial Android Text to Speech

speech to text banner

I have created a simple app to demonstrate this tutorial. Below is the screenshot of the app which contains a simple button to invoke speech input and a TextView to display the converted speech text.

android speech to text

So let’s start by creating simple app.

Sample Application

1. Create a new project in Eclipse by going to File ⇒ New ⇒ Android Application Project and give required information.

2. Open strings.xml located under res ⇒ values and add below string values.

<?xml version="1.0" encoding="utf-8"?>
    <string name="app_name">Speech To Text</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="speech_prompt">Say something&#8230;</string>
    <string name="speech_not_supported">Sorry! Your device doesn\'t support speech input</string>
    <string name="tap_on_mic">Tap on mic to speak</string>

3. Open colors.xml located under res ⇒ values and add below colors. If you don’t see colors.xml, create a new file and add the values.

<?xml version="1.0" encoding="utf-8"?>
    <color name="white">#ffffff</color>
    <color name="bg_gradient_start">#31244e</color>
    <color name="bg_gradient_end">#6b394c</color>

4. Now open the layout file for main activity(activity_main.xml) and add below code to create a simple layout.

<RelativeLayout xmlns:android=""
    android:orientation="vertical" >

        android:textStyle="normal" />

        android:orientation="vertical" >

            android:src="@drawable/ico_mic" />

            android:textStyle="normal" />


5. Finally open your and do the following changes. In simple adding speech input will be done in two steps.

Step 1: Starting RecognizerIntent
First we need to create a RecognizerIntent by setting necessary flags such as
ACTION_RECOGNIZE_SPEECH – Simply takes user’s speech input and returns it to same activity
LANGUAGE_MODEL_FREE_FORM – Considers input in free form English
EXTRA_PROMPT – Text prompt to show to the user when asking them to speak

Step 2: Receiving the speech response
Once the speech input is done we have to catch the response in onActivityResult and take appropriate action needed.

package info.androidhive.speechtotext;

import java.util.ArrayList;
import java.util.Locale;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	private TextView txtSpeechInput;
	private ImageButton btnSpeak;
	private final int REQ_CODE_SPEECH_INPUT = 100;

	protected void onCreate(Bundle savedInstanceState) {

		txtSpeechInput = (TextView) findViewById(;
		btnSpeak = (ImageButton) findViewById(;

		// hide the action bar

		btnSpeak.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {


	 * Showing google speech input dialog
	 * */
	private void promptSpeechInput() {
		Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
		intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
		try {
			startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
		} catch (ActivityNotFoundException a) {

	 * Receiving speech input
	 * */
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		switch (requestCode) {
			if (resultCode == RESULT_OK && null != data) {

				ArrayList<String> result = data


	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(, menu);
		return true;


Run the app in a real device. Make sure that the device has good internet connectivity while you are testing.

Enabling Offline Mode

Right now all the devices are not supporting offline speech input. However you can follow this discussion to enable offline speech input for supported devices.

I have downloaded speech input packages on my Nexus 5 and offline speech is working fine.

1. On your device go to Settings -> Language and Input. Click on icon on Google voice input.
2. Under ALL tab select the language you want to download.
3. Once the language package downloaded, you can see it under INSTALLED tab.

android speech to text offline mode
android speech to text offline mode
android speech to text offline mode
Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk:
  • Abhishek

    Nice one Ravi

  • Dinesh

    Nice Post 🙂

  • pawan

    Thumbs up 🙂
    Please provide a tutorial for Sending a list of contacts (phone and sim) to server and how to receive the same from server

    • Hi Pawan,

      Thanks for the suggestion. I’ll try to write it on next week. Uploading them to a server is different topic though, I can explain reading part from SIM/Phone.

      • Pawan

        Thank you Ravi.
        I’ve done an application for displaying a list of contacts but i’m unable to upload and download the list of contacts to and from server respectively. It will be helpful for me if you provide a tutorial for the same. Waiting for the coming week . Thanks in advance

  • Ravi sir, Is there any way to change Google’s stock voice recognition UI ??

  • LouisG

    Can i see your bg_gradient.xml file, i don’t really understand how write it..

    • Oops! I missed it. I’ll update the article.

      Here is the code for gradient bg

      • Aveena

        i want ico_mic.xml please

        • Fattur

          change it with
          And it works dude

  • tEi

    Looks awesome, gonna try it. Many thanks (=

  • Rebecca Wu

    Sponsored Review Inquiry


    This is Bennie from EaseUS Software Company, a leading software
    provider for data backup and recovery.

    We’re recently looking for sponsored reviews. And it occurred to me
    that you might be interested in.

    You can keep your authentic thoughts in the review.

    How do you quote for writing one review with two links?

    Giveaway is also available to us if you’re interested in.

    Please contact if you have any suggestions for cooperation.

    Best regards
    Chengdu Yiwo Tech Co., Ltd.

  • Hi, thanks for your tutorials. From NO-programmer to a beginner, a huge credit goes to your tutorials (actually just after Google and Stackoverflow).
    Sorry for being off-topic, but I am looking for Pagination of TextView for Android (something like e-book reader). Just wanted to know, if you have made any tutorial/demo of that? All the available demo like pageturner etc. are way too complex for me to understand.
    Or, if you can point me to any other site from where I can get the basic idea for making it?
    (will wait for your reply)
    Dr. Atul Tiwari

  • guy

    i did not understand this step

    ACTION_RECOGNIZE_SPEECH – Simply takes user’s speech input and returns it to same activity
    LANGUAGE_MODEL_FREE_FORM – Considers input in free form English
    EXTRA_PROMPT – Text prompt to show to the user when asking them to speak

    from where i got those .??

    • ali

      i want ico_mic.xml please

      • Fattur

        change it with
        And it works

    • hafoosa

      from code …
      it is there in code

  • hafoosa

    i do all steps but not work … what is wrong ???

    it say >Sorry! Your device doesn’t support speech input

    • Manraj

      There is no problem at all with the app that you created with Eclipse but the problem is that your phone doesn’t support Voice Recognition.Try getting a new phone that supports Voice Recognition and then try to compile and run the app on the device or maybe run the app on Eclipse.But if you would want to run the app on Eclipse,you would require a powerful PC or Laptop as the Android SDK downloaded needs a powerful PC.

      Hope this helps you.

  • Waseem

    How to implement pdf to speak in android

  • Tirsa Aprillia

    I need help you and I have sent it to you. Thanks before

  • Tirsa Aprillia

    How to make a speech recognition with function start and stop to speak. Please help me, I need the code

  • fuck me too

    Is internet permission not required?

  • fuck me too

    Excellent Tutorial! You rock dude/

  • Aryan

    What can I put in place of LANGUAGE_MODEL_FREE_FORM to change the language of input. Can it be auto recognized?

  • webdevlamp

    very nice post

  • Mayur

    How can i convert japanese into Text. I tried saying few japanese sentences but unable to get it in japanese text. I even downloaded the japanese language pack in phone. Please help me.


    hello sir thanks for helping.
    im new in android development im trying to make an app which listen our voice n make to text of it ..
    here i wann know how to make “append code” to acccept full speech and give it as notes..
    thank you

    • KASMIN

      thanks. i got solution
      i used : tv.append(getResult());

  • chlong chlong

    Hi, How I could implement this to your tab fragment? anyhelp would do…

  • Rahul

    Hi Ravi In this application process speech online why network permission is not unabled in manifest file

  • Sitters

    How can I add a confirmation before? such as Did you say “Hello World” (yes or no)?

  • Ena

    hello, how do you destroy it? i mean, i think it’ll have an error that services are leaking or something? i haven’t seen you closing it in onDestroy

  • shobin kumar

    Hello Ravi,I want to know that it requires internet connection??? I want to do this without internet conmnection..Please help

    • Marcos Willians

      This code does not worked for me too…

      I guess that this is one more fake “Now voice recognition offline in Android!”

      The offline recognition worked for me in other app like “notepad” but dont work with this code. Online works, offline no, sad but true.

  • Fattur

    Hi, Thanks for great guide. But there are some things. First Download Code button doesn’t works. Secondly it gives an error at
    So I think we need ico_mic.xml. But I couldn’t find it in your codes. If you share it I would be gladly appreciated. Thanks a lot

    • Fattur

      Oh, NVM for the Second one. But it should have changed with

    • you can just replace it with your ICON… just write
      @drawable/icon_image1 instead of @drawable/ico_mic

  • Sukamal Das

    hey this is great thanks…can u tell me how to get this voice file

  • santosh keshari

    Hi Ravi, google voice recognition engine does not recognize medical terms. I need to implement app to detect medical terms. Which engine shall i use? Do you have any ides?

  • Yoshua Rudy

    Hi, Ravi I already press the subscribe button but I didn’t receive any email regarding confirmation of my subscribtion

  • Laércio Metzner

    You did a great Job! I’m looking for some how to get just Letters and Numbers, not full words nor sentences. My users are going to enter information just like ‘AA001’, ‘BC022’, ‘AD011’, and I still had not figure out how to get it.

  • karuna thevar

    ” your device doesnt support speech to text “, I am getting this error

  • Gnana poobalan

    Does it work on Android 5 with offline mode in micromax android one device?. I need to know about it. Any Suggestions would be appreciated..

    Thanks in advance,

  • azad

    i want create apk speech to text can you help me

  • Mirko Pontoriero

    Hi, I would like to know why this App not work offline? I have a NEXUS 5 and I following the code also the screenshot example but not work. I hope that someone answer me early. Thanks

    • Speech to Text needs internet. When we give speech to app, it connect to google services and translates audio to text.

  • Nikhil

    Hi Ravi, I tried implementing offline support as you have indicated. I downloaded the packages, but still offline support is not working for my app. The app works perfectly when its online…. Any suggestions?

  • Mangesh Panchwagh

    I have a question When spoken words are converted into text, how to store it
    into a text file. So that I can use it(text file) later.

  • Arifin Firdaus

    Hi Ravi, How can I input voice with another language other than english? Can anyone tell me???

    • Arifin Firdaus

      i found it (change the primary input voice) in settings -> Language & input -> Voice input(under the speech section).

  • brahmy

    voice search miss understanding problem i am facing sir.suppose if i wana speaking R then it is understanding like “are” and then it’s displaying like resolve this problem.

  • Adam

    thank you Mr. Ravi Tamada for this tutorial. it’s helpful code,

    I have one question: how I can start voice recognition directly when button clicked (without using Intent).
    do you have any Idea how I can do this?


  • shivam

    hi Ravi i need your help in developing some android apps i want to interconnect two apps for sharing some details or data using mobile network not in WiFi or Bluetooth but i can’t understand how to implement can you help me for implementation………….

    • Are the two apps installed on same device?

  • Lonr

    Question: How can i implement voice trigger input just like, “ok google” in Android’s google app?

    • Антон Рудько

      start function promptSpeechInput() in onCreate without onClick and wait answer “ok google” only before find another text… sorry me English)))

  • Wiam

    It’s awesome. Thanks a lot

  • how can I get recorded voice and text at the same time?

  • Suvojit

    Hi, can we convert the audio from a video and convert it to text using Speech to Text API in Android ?

  • Adjei Bernice

    I am have been able to develop an e-voting android application but my supervisor wants me to add automatic speech recognition feature. I have no idea where to start. Should i create a new class for the ASR and call the methods in the OnCreate() or what should i do. Please help

  • Hitesh Kumar Sahu

    If you dont want to show annoying prompt dialog then you can look into my repo. . I tried to store my learing in that POC

    • BuddySteve

      Can you at least spell correctly so we don’t have to try and figure out what you’re saying?

  • Shubham Kulkarni

    I got your whole code but I m not geting that which api u used for conversion of speech to text in thr????

    • nafees ahmed

      there is no api used

      • Shubham Kulkarni

        Sir can u plz explain what is recognizer intent????

        • Shubham Kulkarni

          Coz I want to build a android app for deaf people, and I don’t want to use any avlbl api

  • vikash kumar

    How can I use different different icon for different purposes.Like one icon on tap gives information about the nearby malls .

  • Shubham Kulkarni

    while executing the code I m having “Rendering Problems Exception raised during rendering: com/android/util/PropertiesMap” what should I do??

  • Arun Kumar

    hai ravi
    impressive projects. wish your work should continue for long time.
    i design a project in which user could feed the column values using
    voice. for example i have 4 edittext in which i should get the values using
    speaktotext methode.and send the same to php,mysql server.
    how can i get separate speaktotext in each edittext when it got focus.
    current speech converted to text in the edittext

  • Olive Paul

    Hi Ravi,
    Rajesh bhaiya is my friend. I hope u r fine. I’m too an Sr Android Application Dev…….Update your article on evry wk…… 🙂

  • madhu

    Internet permission is not mentioned in the file how can you mention int the post
    that we need have good internet connection

    • When use Intent to launch the third party app, you don’t need to mention the Internet permission as the other app itself having it inside the app.

  • Tawsif Siddiqui

    I have been trying to create a voice recognition app and this has been a great guide for me. But I was wondering if you have any idea or advise about how to implement Audio Capture function with it? Because, I want to convert speech to text and at the same time record the audio like Ok Google history!

  • jaya sachan

    sir can you give me apk file of this speech to text app?? i really need it.

  • Vinayaka SP

    Hi Ravi, as usual in my college projects your tutorials come handy every time.
    This time i need a little input from you.
    I want to make an app where it should run recognizer as service in background (even when screen is off). And when a particular keyword is spoken it should trigger some series of actions. Just like “Ok Google”.
    but i’m not getting where to start to achieve what i want. I read about android.service.voice (voice interaction api) AlwaysOnHotwordDetector. But as a newbie in android field i’m not able to code fully using just android website documentation.
    Please help me as soon as possible

  • Sergio Antonio Sánchez Camarer

    Hi Ravi, Do you know if you want to put two or more languages into RecognizerIntent? To recognize two or more languages?

    PD: reply me to

  • Navin Das

    Hello! How to activate the listener without clicking the button. I want it to listen just with some triggering word like “HelloApp”

    • Dorian Waite

      Initialize the listener in the onCreate function, that way when the app launches it will start listening. At that point you create another function that gets user input from there, and if the user input contains your trigger word it then goes on to document what the user says. Quite simple.

  • Sarath Raj

    How to run the app in the device? I have done the coding as well as did the changes in the phone.

    • Use the USB to debug the app. Connect your mobile using USB cable.

  • Gibran Pinacho

    Thanks, the implementation is very easy. =)

  • Sarath Raj

    Its showing as installed in my device. But I am not able to find it out in my device

  • very use full source

  • Jay R Cabauatan

    Is anyone here knows what algorithm is used in Google Voice API or in this API, how the algorithm being applied and what is the background and description of algorithm being used?we are badly needing it for our thesis project entitled AVIS: An Artificial Intelligence Voice Command and Information Gathering Sentinel Using Arduino Device for Persons with Disability. Our final defense is coming this January but then we dont have an algorithm yet.

  • Angga Prabawa

    can i get string of text result to put into database mysql? how to implement it? very useful

  • can cel

    Hi Ravi, I want to make voice assistant(offline) with my own language(Burmese).What I need to know?Where can I start?

  • Ismail Wafaa

    please how do we implement background services?

    • For which purpose you need background service?

  • deepanshu wadhwa

    Hi Ravi,

    First of all thanks for great tutorial.
    I have small query suppose if i have one common button for voice on top and multiple (say 100) Edittext. I would like to know that how to handle this scenario. For example If i tap one Edittext and press voice button so it’ll map with same edittext and so on for other fields.


  • Mithilesh Izardar

    Thank you very much for the tutorial.

    I am facing an issue with below code.

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    // intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    // RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    // intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    // intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
    // getString(R.string.speech_prompt));
    try {
    startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException a) {
    Toast.makeText(getApplicationContext(), “not supported”,

    If you see the code I have commented the extra flag for EXTRA_PROMPT, EXTRA_LANGUAGE, EXTRA_LANGUAGE_MODEL and it is working fine but the problem I am facing is that It still shows two dialog second dialog states “Tap to speak”. how can I remove that dialog Please help

  • Harshit Agarwal

    Hey ravi, I am getting the error “Your device doesn’t support speech to text conversion”
    whats the way out?

    • Which OS and device you are testing it on?

      • Harshit Agarwal

        ok, i got that , actually i hadn’t installed google speech recognition app on my phone. thanks for your help

  • Harshit Agarwal

    Hey , i wanted to programmatically transfer small data from one android deice to another both of which have installed my android app, do you have an idea how to proceed with it?

    • You can do it in multiple ways.

      1. Use bluetooth to transfer data

      2. Use PHP & Mysql services to send data

      3. Use FCM with php to send data

      • Harshit Agarwal

        I didn’t want to used bluetooth because then we are bounded by distance.
        For second and third options, do we need a server in between or we can directly transfer data via internet.
        Also how come android phone support php, we write the application in JAVA.

        • Rares-Mihai Chelariu

          Android nor Java do not supp php. You must create a REST API that provides you the data (for a specific get/post url on a php file on the web, you get a query result or smth like this).

  • Mayur Bhandari

    Can I pass this text to any other application. Eg.: If I say search iPhone in flipkart then the flipkart app should open and search for iPhone directly. Is it possible??? Your reply would be greatly appreciated. Thanks alot

  • James Harrison

    Hi as soon as I hit my record button in the emulator it takes me to the screen that says speak now for literally about half a second, and then changes to this I’m not sure why

    my emulated device is a nexus 5, API:25, target:Android 7.1.1

    thank you

    • Leo LI

      Hi I got exactly the same problem. Have you figured it out how to resolve it yet? Thank you!

      • James Harrison

        Hey no I haven’t figured it out yet if I do ill let you know

        • Sanjay Adhikari

          Run it on a real device. I don’t think emulator’s mic takes input.

          • Salma Yossef


    • Farrukh Saleem

      I want to create a login page with the help of speak to text. for example when I say action user name AAA okay then it catch only AAA and write it in user name field similarly password when I say action password 123 okay then it goes to password field and write 123 in the password field.
      When I say action he start listening voice and when I say okay then he stop listening

  • Ankita Pendse

    Sir,I want to make an app which takes speech input…converts it to text…and uses this text for further processing.Or can i use google speech to text and fetch the text for my further process???
    Can this be done???

  • Harshit Agarwal

    Hey ravi, i was trying to build an app that runs 24*7 on our mobile in background and generates an event on double tap detection, do you know the way out?

  • Rucha D

    Hello Ravi,this application is wonderful. But i want to send text message. Actually i have executed this code but furthermore i want to send this text to other person.Can you plz tell me how can i join messaging app and this app by intent??

  • Dzurrotul Arifah

    Ravii i wanna make apllication chines dictionary using voice rcognition frong indonesian language to chinese… or maybe u can give me the tutor about how to translete from indonesia to chines or english using voice recognition. Thanx

  • Dzurrotul Arifah

    assalam ravi…
    how to make or the coding if i wanna make translate from indonesia to china using speech to text thanx before.

  • Ankit Chaudhary

    Hello Ravi, I want to make an android application Friend Mapper. I want that location must be updated automatically after 1min or 2 min and we can check our friend’s location on google map. How can we do that..

    • Dravit Lochan Gupta

      1. Google map has already done that.
      2. you are looking at the wrong place. Look for a tutorial on location listener.
      Hope this helps 🙂

  • Fahad Ahmed

    I want to create an application which takes speech as an input and returns a voice as the output..
    anybody has done it in Android plateform then please give me the working project code. I will be very thankful.
    I have done that for iPhone in 2014 but i lost the code.

  • Patrick Fitzwater

    One of the errors I am getting is “can’t resolve symbol R”

    • Shani Patel

      Sync your project with gradle symbole is on title bar just beside of AVD manager and that solved your problem….

  • Kyoto

    Hi Ravi,
    Is it possible to test the speech recongition in offline mode on an emulator? I coudn’t find “download language” on my Nexus5x emulator’s configuration.

  • m usman ghori

    how to create a library of custom words for speech to text application ?

  • Vitor L

    You are amazing man, thats a great help thanks!

  • Rahul Khanna

    Can we customise the Google dialog that appears?
    wanted to remove Google written in it if possible

    • Salma Yossef

      I want that too 🙁

  • Sezer KARTAL

    Hello. Can the app do text to speech in Turkish language?

    • Dravit Lochan Gupta

      intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
      instead of Locale.getDefault(), enter Locale.tr_TR

  • Bohati Mulyadi

    hy brother i have problem… if i run this project i have “Unfortunately aplication has stoped”

    • Iuri

      Try remove getActionBar().hide();

      • Yes, getActionBar() is deprecated.

        • Pujan Shah

          I want to recognize voice continuously and want to set text as soon as user say something.Can you please help me for this?


    haii..can u also provide code for image recognition to voice

  • anon

    hello, is there any way to make it offline? so if the user has no internet he can still use the app

  • trong hoang

    I want use Speech Recognizer without dialog, So how to do it?
    Thank you!

  • Salma Yossef

    I want speech to number code
    any body can help me ?
    thanks a lot

  • Manasi Joshi

    Hi i want the text string generated after speech to text and pass it to the other form.How can i do that .Could you please help

    • Dravit Lochan Gupta

      by other form do you mean other activity?

      • Manasi Joshi

        ya activity

        • Dravit Lochan Gupta

          once you’ve succeeded in STT, convert it into string and pass as extra intent to new intent.

    • Şahin Aygün Yıldırım

      I think you can do it by putting extra.

  • Muhammad Waqas

    hi, thanks for such a nice tutorial, I have a few questions ..
    Google’s Speech to text API is not free, but as this feature is built-in , so will google charge something for it?
    secondly, I want to not only convert speech to text but also want to record the audio . can I do that by changing your code in a way that it also saves the audio input..?? thanks

    • Kishan Kant Kataria

      hi, any info about the speech to text api charges when using built in

      • Muhammad Waqas

        As this feature in in-built for android , therefore it doesn’t charge anything.

  • bapSoon

    hello i tried to run it in my phone but it doesn’t work when i hit the button. I believe it doesn’t recognize my voice?

  • The Xuan Bui

    Thanks man. ;))

  • Farrukh Saleem

    I want to create a login page with the help of speak to text. for example when I say action user name AAA okay then it catch only AAA and write it in user name field similarly password when I say action password 123 okay then it goes to password field and write 123 in the password field.
    When I say action he start listening voice and when I say okay then he stop listening.
    if any one have knowledge about it then please share here or send me on my personal e mail address

  • Dilash Arora

    sir this,dialg box appears for a long time,i want to close it as voice stops,and display the resut
    lt as soon as voice is completed

    • Pujan Shah

      Did you get any solution?

  • shwettha

    hey…where will be output text will be displayed

    • Ovalman

      Change textcolor in resources to black or create a new resourse called “black” and set color to #000000

  • Ovalman

    Brilliant Ravi, so easy.

    Is there a way to control the button via speech ie like an onSpeechListener? Similar to saying OK Google

    is there a way to utilise speech with the screen off? I’d like to
    create an app that listens in the background but doesn’t wake up the

    • Ayush Gemini

      Have you found any solution ??

      • Mark C

        No Ayush, I’m still looking a solution myself. It may be a problem with Android itself. To use the speech with the screen off means the phone has to be permanently awake and listening which is a big drain on the battery. It’s also a security issue.

        If I find a solution I’ll contact you via this thread (I have notifications set up via Discuss.)

        • Ayush Gemini

          Ok thank you .

  • Rohan

    awesome tutorial

  • Zeeshan Akram

    hi, very nice tutorial. i am using recognizerintent in my current program. have u worked on it before? what i am doing is collecting the spoken words and search thru my array for valid commands and based on that i do actions. im having trouble in making a phone caller with this logic. can u help?

    • What is the the problem?

      • Zeeshan Akram

        can u share ur email address? i will send u my code and explain the logic. im not android expert. this is how i learnt android development: understand the examples, make changes in them to know how they work, to implement anything i search around, understand the code and take out the snippet. im not myself a programmer to write something from scratch

        • Then it will take sometime to figure out things. You need to read and understand correctly. I can’t check your project and give you the solution.

          • Zeeshan Akram

            ok no issues. i have seen your code and did some engineering.
            txtSpeechInput.setText(result.get(0) is basically keeping only the 1st instance of recorded words. i made it get(1) and it showed me the other possible word i spoke. how can i disable the google mic floater that appears when i click on mic? i just want the main application in listening mode without any pop up etc. will it work if i move your promptSpeechInput() code to the onCreate? also im implenting text to speech in same project where the app will communicate to me. in this case, i need to mute speech to text so that it doesnt work when app speaking to me. cna u help me with these two things?
            in my app, i will speak ‘make phone call’ and app will ask me ‘whom you wanna call’…then app will search for the name in address book i will speak and make phone call. ive already done many other similar voice activated actions but this one is more challenging for me

          • Zeeshan Akram

            ive successfully done above. only issue im facing is that how can i pause this fucntion? for my interactive app, my phone makes me speak something and then it answers. i want to disable the speak recognition when phone is speaking and then resume once phone has finished speaking

  • Akash Mishra
    • Is main.xml exist under res -> menu folder? If yes, rebuild the project.

      • Akash Mishra

        No it doesn’t here. What to do?

        • Just comment the error code in your activity.

    • shivam Kapoor

      Akash delete this . It will work

    • Jak

      I’m having the same problem

      • Remove the function or create an xml file under res -> menu folder.

  • Vicky

    can I change the input in android speech to text?
    because I need to make the recorder function, but I can’t do at the same time.

  • Vincenzo Di giovambattista

    Hey, I am using the same code for a speech to text robot controller. It works fine with internet connection on and also offline with airplane mode . Unfortunately my application is running with the wifi connection to the robot which also behaves as a wifi access point. This wifi connection is between robot and smartphone and does not get to the internet, when using the code above the speech to text recognition takes ages ( like 30 seconds ) to get the result, consider that I ve also used the following settings in my code:

    intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);

    But they are useless in my field of application…
    P.S. this seems a regression of one of the latest android upgrade…the code used to work fine a few weeks ago!
    Any suggestion???

    • I am not sure bro. May be you research a bit further.

  • prehatredism

    Ravi, I have a question. The app works fine, but I’m trying to figure how to take the data from TextView and export it into another format. My assumption is that TextView represents string data. Am I accurate?

    • What is the expected format you are looking for? TextView represents string data only.

      • prehatredism

        I WANT to send a string of data (from TextView) into Google Cloud which, from what I can tell only accepts csv file (databases-i.e. Biq Query).

  • reddy_077

    Are there any changes in above code to use in offline mode. And how to ensure that the user has downloaded the language. And can we do this in user mobile from our application.

    • reddy_077

      @ravi8x:disqus can u help me in this issue

  • tol

    Hi. How can I change the transparency of a standard dialog box with a microphone.

  • Inderjit Singh


  • Aizen Rya

    thankyou. How I can run it in emulator ??

  • rnmisrahi

    The way I want to modify the app is as follows: I want the user to stop the transcription manually, by selecting the same or some other button, instead of the transcription just stopping after a pause of a few milliseconds. To achieve this, I actually made it loop several times, meaning, after there is a pause I get the transcription and append it to a result string.
    This works fine, except for the pause that there is between recording and recording and the annoying beep. I guess I need to have a thread in the loop where I let the app to record while I get the result and append it to the final transcription.
    I don’t know is this is possible at all.
    Any ideas?

    • Sulaiman Abdul Quadeer

      I want to achieve the same (button to stop the transcription) can you please share your code….. Thankyou in advance.

    • Evs tester

      yes that’s possible , you will
      call that intent in service and mute that beep using audio manager 🙂

  • Luis M

    Wow, this is amazing, Can I use this code freely or it has Copyright? Because I only copied the part to make the grandient, and the colors.xml code.

    • There is no Copyright. You can use them freely.

  • Pratik Bakane


    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    if (resultCode == RESULT_OK && null != data) {
    ArrayList result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    String dup1=t1.toString();
    String my1=”Trains available”;

    Intent in1=new Intent(this,tavb.class);

    • What is the expected output and the current output?

      • Pratik Bakane

        expected output is the activity tavb should start as soon as the string Trains available matches plss help

  • Marlon Antonio Medina Taguican

    can you add predictive text just like ok google.

  • shiva palani

    Hi,bro. I have a doubt. How to convert speech to video directly without using textview or any other text options. Actually, I’m trying to create an app for deaf & dumb people in which audio message will be converted as sign language video. That too tamil voice should be given as input. Can u help me out?

  • Pratik Bakane

    i am devloping app or the blind people my requirement is app should trigger with volume up button or some kind of similar key how can i do it ?

    Plzz help sir

    • Marlon Antonio Medina Taguican

      I developed exact app, when press volume up speech recognition turn on / off, when press volume down tts turn off.
      public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
      Toast.makeText(this, “Volume Down Pressed”, Toast.LENGTH_SHORT)
      return true;
      if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
      Toast.makeText(this, “Volume Up Pressed”, Toast.LENGTH_SHORT)
      return true;

      else {
      return super.onKeyDown(keyCode, event);

  • PSL

    sir in offline mode only type english language.WHY?

  • Tania

    I tried to create this app, I use android studio when I enter the codes gives me errors and if I close the project and I open it completely disappears the design how can I solve this problem?

  • Ramkesh Yadav

    Hi sir, is it possible to trigger speech to text action without clicking at “Tap on mic to speak”? like “OK GOOGLE” Feature.
    i just want the app is always in listening mode and user just start speaking and its starts matching without any button click .
    please help me its URGENT..

  • Shreshth Neema

    Please suggest, How to set hindi as language from code?

  • Nicolas Gorse

    Very nice tutorial. However, I found out that it works only up to api 24. At api 25 it fails right away when you press the button, with the network error code. Any idea why?

  • kishor

    hi your code is not work on android level 25

    • Gadepalli Aditya

      It is working in Nougat

  • Niyazi Toros

    I need 2 apis and can pay 100 USD for voice to text and face recognition source code for Dart Flutter. Please contact me at: niyazi . toros at gmail . com

  • kelum Prabash

    Hi Could you please tel me that how can we use this for another language. As an example, i want to detect “Sinhala” speech and convert it to “Sinhala” text

    • Sathindu Kavneth

      final Intent mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
      mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
      mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, “si-LK”)

  • mridulganga

    Lol anyone can use the intent.

  • Hari Yadav

    It is working Fine but it also shows a toast saing saving audio to my email address….can u explain whats that ??? please reply asap

  • Alok singh

    hello how can i remove toast which is shown every time

  • Rawall

    can i make it in urdu?
    and if it’s possible how should i

  • Aldy Putra W

    Hi Sir, I successfull your app to my source code, but i want to make action when i say certain word like “open new activity” and if i say word except that, the app will do nothing.
    plz help sir thx 🙂

  • Chirantan Thakkar

    Thanks Ravi.

    Very helpful tutorial.

  • boomatjang

    Thanks Ravi

  • Shawon Shams

    Hello sir, How can I use this in Service activity. I try this one mSpeechRecognizer.setRecognitionListener(new RecognitionListener() {

    But, its not working. I want to use this tutorial in the Service activity. Please help me.

  • Shawon Shams

    Hello, Thank you very much for the tutorial. In androidhive there is a tutorial about Floating View Service. I want to use this Speech to text tutorial in Floating view service. But, this one is not working.

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    if (resultCode == RESULT_OK && null != data) {

    ArrayList result = data


    By the way, sir I am new in Android development and I am in class X now. So, you can realize that I am weak in Programming. Please help me. When user click the Mic then Google Speech to text service will activate. Please help me.

  • vaibhav

    Even after implementing the whole code, My app keep on crashing. It’s not even opening.

  • Libz Antz

    i need it long time…i want close it it possible??

  • yagnesh

    i need Text to speech for Hindi language it is possible?
    i have try this all possible solution but not working please help me


    m_TTS.setLanguage(new Locale(“hi”));


    m_TTS.setLanguage(new Locale(“hin”,”IND”,null));

  • Umair

    i do wanna use some custom word condition like if i say rent,sale in my speech then my speech just recognize these words how is that possible please

    • Yuz

      Look up regex. Use the string that the speech to text built then parse the string with regex looking for “rent” or “sale”.

  • Jvd

    Hi , I want to implement the speech to text IME in my custom keyboard when the mic icon on the keyboard click.The result shall be shown in fig.i searched a lot but didn’t find any solution. I am not able to use StartActivityforresult in myinputservice for SpeechRecognition.any hints are highly appreciated.

  • Deepak Sharma

    Is it free or paid ?

  • Adam

    Hello sir please help me when i add code to (activity_main.xml) i get this error message >> ( Couldn’t resolve resource @drawable/bg_gradient ) << can you help me please thanks in advance 🙂

  • Prem Chand

    Hi @ravi8x:disqus Its not working with video call, Actually i want to convert my spoken words text when i am on video call is it possible in it.

  • anil gupta

    Offline Voice recognizer .. not working as per your suggestion..

  • Serdar Yılmaz

    Thanks for tutorial.

  • Serdar Yılmaz

    I have a question. Can we use this code blog for commercial using. I mean for example the app including this code that will be published on Play Store. Could you help ?