Android Speech to Text

Android Speech to Text

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 tutorial Android Text to Speech

Example

In this tutorial, we are going to learn how to use convert Speech/Voice to Text.

Video Demo

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. By default my activity is MainActivity.java.

2. First create a layout in xml file naming activity_main.xml that contains Button for starting voice recognition and a ListView to display the result.

3. Now open your MainActivity.java and add the following lines. There are only two steps by which we can achieve our goal :

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.

Note : Before doing anything we have to check if the device support Speech Reocgnizer or not.

4. Now, you are all done, run your app and you will get the output as shown in video.

Thanks. :)

Download Source Code – >

 

Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)