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"?>
<resources>
    <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>
</resources>

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"?>
<resources>
    <color name="white">#ffffff</color>
    <color name="bg_gradient_start">#31244e</color>
    <color name="bg_gradient_end">#6b394c</color>
</resources>

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_gradient"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/txtSpeechInput"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:textColor="@color/white"
        android:textSize="26dp"
        android:textStyle="normal" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="60dp"
        android:gravity="center"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/btnSpeak"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:src="@drawable/ico_mic" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="@string/tap_on_mic"
            android:textColor="@color/white"
            android:textSize="15dp"
            android:textStyle="normal" />
    </LinearLayout>

</RelativeLayout>

5. Finally open your MainActivity.java 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.app.Activity;
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;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		txtSpeechInput = (TextView) findViewById(R.id.txtSpeechInput);
		btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);

		// hide the action bar
		getActionBar().hide();

		btnSpeak.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				promptSpeechInput();
			}
		});

	}

	/**
	 * Showing google speech input dialog
	 * */
	private void promptSpeechInput() {
		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, REQ_CODE_SPEECH_INPUT);
		} catch (ActivityNotFoundException a) {
			Toast.makeText(getApplicationContext(),
					getString(R.string.speech_not_supported),
					Toast.LENGTH_SHORT).show();
		}
	}

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

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

				ArrayList<String> result = data
						.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
				txtSpeechInput.setText(result.get(0));
			}
			break;
		}

		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, 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
Ravi is hardcore Android programmer and Android programming has been his passion since he compiled his first hello-world program. Solving real problems of Android developers through tutorials has always been interesting part for him.
  • 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
          @android:drawable/ic_btn_speak_now
          And it works dude

  • tEi

    Looks awesome, gonna try it. Many thanks (=

  • Rebecca Wu

    Sponsored Review Inquiry

    Hi,

    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 bennie@easeus.com if you have any suggestions for cooperation.


    Best regards
    Bennie
    Chengdu Yiwo Tech Co., Ltd.
    http://www.easeus.com
    http://www.partition-tool.com
    http://www.todo-backup.com

  • 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)
    Thanks.
    Regards,
    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
        @android:drawable/ic_btn_speak_now
        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.
      -Manraj

  • 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.

  • KASMIN

    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
    android:src=”@drawable/ico_mic”
    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
      @android:drawable/ic_btn_speak_now
      Thank’s

    • 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,
    -poobalan

  • 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

    hey
    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 this..how 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?

    thanks

  • 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.https://github.com/hiteshsahu/Android-TTS-STT . 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?
    Thanks

    PD: reply me to seransaca@gmail.com

  • 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

    https://uploads.disquscdn.com/images/74a9f1f04b58b123c9bffa6eaea820617976c560776a818ba6497deb322e9577.jpg

    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.

    Thanks,
    Deepanshu

  • Mithilesh Izardar

    https://uploads.disquscdn.com/images/28bcc30a1f5168f3e06c022c39cd5feae2521f5e2c4b953809475359d81d8b3f.png https://uploads.disquscdn.com/images/5d5b8a5d756ae200c114e8b0dc8890a28cc0f69bfe9b59f10c8aae0079a1a439.png

    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”,
    Toast.LENGTH_SHORT).show();
    }

    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

    https://uploads.disquscdn.com/images/037fa05adcaf37aea9a9b4761597e23b7ae9d2274e113f695f8e61c44e5bc39b.png

    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

            i RUN IT ON MY DEVICE AND HAVE NO PROBLEM

    • 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 file..one 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?

  • ROHILA K

    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

    hello
    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 farrukhsaleem8915@gmail.com

  • 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

    And
    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
    screen.

  • 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

  • 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);
    intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,1000);
    intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,4000);
    intent.putExtra(RecognizerIntent.EXTRA_WEB_SEARCH_ONLY,false);
    intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE,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???
    Thanks!

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