Вы находитесь на странице: 1из 42

Tell us what you think and win prizes in the Tuts+ Annual Survey 2014.

Dismiss

All Topics Find tutorials, courses, and more...

Code Categories Learning Guides

ANDROID SDK

Android SDK: Build a


Speak and Repeat App
by Sue Smith 19 Jun 2012
34 Comments

5 1 18

The Android platform provides support for both speech recognition and speech
synthesis. In this tutorial, we will create a simple Android app which allows the user
to speak, attempts to recognize what they say, and then repeats what was
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
recognized back to them using the Text To Speech engine.

We will use the same technique for the TTS engine as we did inAndroid SDK:
Using the Text to Speech Engine, so the focus of this tutorial will be on the speech
recognition element. Both speech recognition and synthesis are relatively easy to
implement on the Android platform, so you should be able to achieve the steps in
this tutorial even if you are an Android beginner.

Step 1: Start an Android Project


Create a new Android project in Eclipse. Alternatively, if you want to implement the
speech recognition functionality in an existing app, open it instead. For this tutorial
we have a minimum SDK version of 8, and you do not need to make any particular
additions to your Manifest file, the default contents should suffice.

Step 2: Define the User Interface


Let's start by defining the user interface. When the app launches, the user will be
presented with a button. On pressing the button, the app will prompt them to speak,
listening for their voice input. When the speech recognition utility processes the
speech input, the app will present a list of suggested words to the user. As you'll
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
know if you've tried speech recognition as a user, the recognizer is not always
accurate, so this list is essential. When the user selects an item from the list, the
app will speak it back to them using the TTS engine. The TTS part of the application
is optional, so you can omit it if you prefer.

The app is going to use a few text Strings as part of the interface, so define them
by opening the "res/values/strings.xml" file and entering the following content:

1 <resources>
2 <string name="intro">Press the button to speak!</
string>
3 <string name="app_name">SpeechRepeat</string>
4 <string name="speech">Speak now!</string>
5 <string name="word_intro">Suggested words&#8230;</
string>
6 </resources>

Of course, you can alter the String content in any way you like.

Open your "res/layout/main.xml" file to create the main app layout. Switch to the
XML editor if the graphical editor is displayed by default. Enter a Linear Layout as
the main layout for the app's launch Activity:

1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android
2 android:layout_width="fill_parent"
3 android:layout_height="fill_parent"

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
3 android:layout_height="fill_parent"
4 android:orientation="vertical"
5 android:background
="#ff330066"
6 android:paddingBottom="5dp" >
7
8 </LinearLayout>

The Linear Layout contains various style declarations including a background color.
Inside the Linear Layout, first enter an informative Text View:

1 <TextView android:layout_width="fill_parent"
2 android:layout_height="wrap_content"
3 android:text="@string/intro"
4 android:padding="5dp"
5 android:textStyle="bold"
6 android:textSize="16dp"
7 android:gravity="center"
8 android:textColor="#ffffff33" />

Notice that the Text View refers to one of the Strings we defined. It also sets various
display properties which you can alter if you wish. After the Text View, add a button:

1 <Button android:id="@+id/speech_btn"
2 android:layout_width="match_parent"
3 android:layout_height="wrap_content"
4 android:text="@string/speech" />

The user will press this button in order to speak. We give the button an ID so that
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
we can identify it in the Java code and display one of the Strings we defined on it.
After the button, add another informative Text View, which will precede the list of
suggested words:

1 <TextView android:layout_width="fill_parent"
2 android:layout_height="wrap_content"
3 android:padding="5dp"
4 android:text="@string/word_intro"
5 android:textStyle="italic" />

Again, this Text View uses a String resource and contains style properties. The last
item in our main.xml Linear Layout is the list of suggested words:

01 <ListView android:id="@+id/word_list"
02 android:layout_width="fill_parent"
03 android:layout_height="0dip"
04 android:layout_weight="1"
05 android:paddingLeft="10dp"
06 android:paddingTop="3dp"
07 android:paddingRight="10dp"
08 android:paddingBottom="3dp"
09 android:layout_marginLeft="20dp"
10 android:layout_marginRight="20dp"
11 android:layout_marginTop="5dp"
12 android:layout_marginBottom="5dp"
13 android:background="@drawable/words_bg"/>

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
The List View will be populated with data when the app runs, so we give it an ID for
identification in Java. The element also refers to a drawable resource, which you
should add to each of the drawables folders in your app's "res" directory, saving it
as "words_bg.xml" and entering the following content:

01 <shape xmlns:android="http://schemas.android.com/apk/res/android
"
02 android:dither="true">
03 <gradient
04 android:startColor="#ff000000"
05 android:endColor="#ff000000"
06 android:centerColor="#00000000"
07 android:angle="180" />
08 <corners android:radius="10dp" />
09 <stroke
10 android:width="2dp"
11 android:color="#66ffffff" />
12 </shape>

This is a simple shape drawable to display behind the List View. You can of course
alter this and the List View style properties if you wish. The only remaining user
interface item we need to define now is the layout for a single item within the list,
each of which will display a word suggestion. Create a new file in "res/layout"
named "word.xml"and enter the following code:

1 <TextView xmlns:android="http://schemas.android.com/apk/res/android
"
2 android:layout_width="fill_parent"
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
2 android:layout_width="fill_parent"
3 android:layout_height="fill_parent"
4 android:gravity="center"
5 android:padding="5dp"
6 android:textColor="#ffffffff"
7 android:textSize="16dp" >
8 </TextView>

Each item in the list will be a simple Text View. That's our interface design complete.
This is how the app appears on initial launch:

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Note: don't worry about the lack of dithering, this is just how it looks in the
DDMS screenshot. On the device itself, the gradient is perfectly smooth.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Step 3: Setup Speech Recognition
Now we can implement our Java code. Open your app's main Activity and add the
following import statements at the top:

01 import java.util.ArrayList;
02 import java.util.List;
03 import java.util.Locale;
04
05 import android.app.Activity;
06 import android.content.Intent;
07 import android.content.pm.PackageManager;
08 import android.content.pm.ResolveInfo;
09 import android.os.Bundle;
10 import android.speech.RecognizerIntent;
11 import android.speech.tts.TextToSpeech.OnInitListener;
12 import android.speech.tts.TextToSpeech;
13 import android.util.Log;
14 import android.view.View;
15 import android.view.View.OnClickListener;
16 import android.widget.AdapterView;
17 import android.widget.AdapterView.OnItemClickListener;
18 import android.widget.ArrayAdapter;
19 import android.widget.Button;
20 import android.widget.ListView;
21 import android.widget.Toast;
22 import android.widget.TextView;

You may not need all of these if you do not implement the TTS functionality -
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Eclipse should highlight imports you have not used so check them when you finish
coding. Extend your opening class declaration line as follows, altering the Activity
name to suit your own:

1 public class SpeechRepeatActivityextends Activity implements OnClickListener, OnInitL

The "OnInitListener" is only required for the TTS function. Add the following instance
variables inside your class declaration, before the "onCreate" method:

01 //voice recognition and general variables


02
03 //variable for checking Voice Recognition support on user device
04 private static final int VR_REQUEST = 999;
05
06 //ListView for displaying suggested words
07 private ListView wordList;
08
09 //Log tag for output information
10 private final String LOG_TAG = "SpeechRepeatActivity"
;//***enter your own tag here***
11
12 //TTS variables
13
14 //variable for checking TTS engine data on user device
15 private int MY_DATA_CHECK_CODE =0;
16
17 //Text To Speech instance
18 private TextToSpeech repeatTTS;

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Inside your "onCreate" method, your class should already be calling the superclass
method and setting your main layout. If not, it should begin like this:

1 //call superclass
2 super.onCreate(savedInstanceState);
3 //set content view
4 setContentView(R.layout.main);

Next, still inside your "onCreate" method, retrieve a reference to the speech button
and list we created, using their ID values:

1 //gain reference to speak button


2 Button speechBtn = (Button) findViewById(R.id.speech_btn);
3 //gain reference to word list
4 wordList = (ListView) findViewById(R.id.word_list);

The List View is an instance variable, accessible throughout the class. Now we
need to find out whether the user device has speech recognition support:

01 //find out whether speech recognition is supported


02 PackageManager packManager = getPackageManager();
03 List<ResolveInfo> intActivities = packManager.queryIntentActivities(
new
04 if (intActivities.size() !=0) {
05 //speech recognition is supported - detect user button clicks
06 speechBtn.setOnClickListener(
this);

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
06 speechBtn.setOnClickListener(
this);
07 }
08 else
09 {
10 //speech recognition not supported, disable button and output message
11 speechBtn.setEnabled(false);
12 Toast.makeText(this, "Oops - Speech recognition not supported!"
, Toast.LENGTH_LON
13 }

We query the environment to see if the Recognizer Intent is present. If it is, we


instruct the app to listen for the user pressing the speech button. If speech
recognition is not supported, we simply disable the button and output an informative
message to the user.

Step 4: Listen for Speech Input


Let's setup the click listener for the speech button we've instructed the app to detect
clicks for. Outside the "onCreate" method, but inside your Activity class declaration,
add an "onClick" method as follows:

1 /**
2 * Called when the user presses the speak button
3 */
4 public void onClick(View v) {
5 if (v.getId() == R.id.speech_btn) {

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
5 if (v.getId() == R.id.speech_btn) {
6 //listen for results
7 listenToSpeech();
8 }
9 }

Now implement the method we've called here after the "onClick" method:

01 /**
02 * Instruct the app to listen for user speech input
03 */
04 private void listenToSpeech() {
05
06 //start the speech recognition intent passing required data
07 Intent listenIntent =new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
08 //indicate package
09 listenIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPa
10 //message to display while listening
11 listenIntent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"Say a word!"
12 //set speech model
13 listenIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.
14 //specify number of results to retrieve
15 listenIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,
10);
16
17 //start listening
18 startActivityForResult(listenIntent, VR_REQUEST);
19 }

Some of this code is standard for setting up the speech recognition listening
functionality. Areas to pay particular attention to include the line in which we specify
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
the "EXTRA_PROMPT" - you can alter this to include text you want to appear for
prompting the user to speak. Also notice the "EXTRA_MAX_RESULTS" line, in
which we specify how many suggestions we want the recognizer to return when the
user speaks. Since we are calling the "startActivityForResult" method, we will
handle the recognizer results in the "onActivityResult" method.

When the app is listening for user speech, it will appear as follows:

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Step 5: Present Word Suggestions
Implement the "onActivityResult" method inside your class declaration as follows:
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Implement the "onActivityResult" method inside your class declaration as follows:

01 /**
02 * onActivityResults handles:
03 * - retrieving results of speech recognition listening
04 * - retrieving result of TTS data check
05 */
06 @Override
07 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
08 //check speech recognition result
09 if (requestCode == VR_REQUEST && resultCode == RESULT_OK)
10 {
11 //store the returned word list as an ArrayList
12 ArrayList<String> suggestedWords = data.getStringArrayListExtra(Recognizer
13 //set the retrieved list to display in the ListView using an ArrayAdapter
14 wordList.setAdapter(new ArrayAdapter<String> t(his, R.layout.word, suggested
15 }
16
17 //tss code here
18
19 //call superclass method
20 super.onActivityResult(requestCode, resultCode, data);
21 }

Here we retrieve the result of the speech recognition process. Notice that the "if"
statement checks to see if the request code is the variable we passed when calling
"startActivityForResult", in which case we know this method is being called as a
result of the listening Intent. The recognizer returns the list of 10 suggested words,
which we store as an Array List. We then populate the List View with these words,
by setting an Array Adapter object as Adapter for the View. Now each of the items
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
by setting an Array Adapter object as Adapter for the View. Now each of the items
in the List View will display one of the suggested words.

If the app successfully recognizes the user input speech and returns the list of
words, it will appear as follows:

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Alternatively, if the app does not recognize the user speech input, the following
screen will appear:

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Step 6: Detect User Word Choices
We want to detect the user selecting words from the list, so let's implement a click
listener for the list items. Back in your "onCreate" method, after the existing code,
set the listener for each item in the list as follows:

01 //detect user clicks of suggested words


02 wordList.setOnItemClickListener(
new OnItemClickListener() {
03
04 //click listener for items within list
05 public void onItemClick(AdapterView<?> parent, View view,
int position,
06 {
07 //cast the view
08 TextView wordView = (TextView)view;
09 //retrieve the chosen word
10 String wordChosen = (String) wordView.getText();
11 //output for debugging
12 Log.v(LOG_TAG, "chosen: "+wordChosen);
13 //output Toast message
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
13 //output Toast message
14 Toast.makeText(SpeechRepeatActivity.
this, "You said: "+wordChosen, Toast.LENG
15 }
16 });

We use the "setOnItemClickListener" method to assign a listener to each item in the


list. Inside the new "OnItemClickListener", we implement the "onItemClick" method
to respond to these clicks - this method will fire when the user selects a suggested
word from the list. First, we cast the View that has been clicked to a Text View, then
we retrieve the text from it. This text is the word the user has selected. We write the
chosen word out to the Log for testing and output it back to the user as a Toast
message. Depending on the needs of your own application, you may wish to carry
out further processing on the chosen word - this code is purely for demonstration.

The user can press the touchscreen or use a trackball to select words in the list.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
When the user selects a word, the Toast message appears confirming it.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Step 7: Setup TTS Functionality
If you do not want to implement the Text To Speech functionality, you can stop now
and test your app. We only require a little more processing to make our app repeat
the user's chosen word. First, to set up the TTS engine, add the following code to
the section in your "onCreate" method where you queried the system for speech
recognition support. Inside the "if" statement, after

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
"speechBtn.setOnClickListener(this);":

1 //prepare the TTS to repeat chosen words


2 Intent checkTTSIntent =new Intent();
3 //check TTS data
4 checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
5 //start the checking Intent - will retrieve result in onActivityResult
6 startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);

Like the speech listening process, we will receive the result of this code checking
for TTS data in the "onActivityResult" method. In that method, before the line in
which we call the superclass "onActivityResult" method, add the following:

01 //returned from TTS data check


02 if (requestCode == MY_DATA_CHECK_CODE)
03 {
04 //we have the data - create a TTS instance
05 if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
06 repeatTTS = new TextToSpeech(this, this);
07 //data not installed, prompt the user to install it
08 else
09 {
10 //intent will take user to TTS download page in Google Play
11 Intent installTTSIntent =new Intent();
12 installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
13 startActivity(installTTSIntent);
14 }
15 }

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Here we initialize the TTS if the data is already installed, otherwise we prompt the
user to install it. For additional guidance on using the TTS engine, see the Android
SDK: Using the Text to Speech Engine tutorial.

To complete TTS setup, add the "onInit" method to your class declaration, handling
initialization of the TTS as follows:

1 /**
2 * onInit fires when TTS initializes
3 */
4 public void onInit(int initStatus) {
5 //if successful, set locale
6 if (initStatus == TextToSpeech.SUCCESS)
7 repeatTTS.setLanguage(Locale.UK);
//***choose your own locale here***
8 }

Here we simply set the Locale for the TTS, but you can carry out other setup tasks
if you like.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Advertisement

Step 8: Repeat the User Choice


Finally, we can repeat the user's chosen word. Back in your "onCreate" method,
inside the "OnItemClickListener" "onItemClick" method, after the line in which we
output a Toast message, add the following:

1 //speak the word using the TTS


2 repeatTTS.speak("You said: "+wordChosen, TextToSpeech.QUEUE_FLUSH,
null

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
This will cause the app to repeat the user's chosen word as part of a simple phrase.
This will occur at the same time the Toast message appears.

Conclusion
That's our complete Speak and Repeat app. Test it on an Android device with
speech recognition and TTS support - the emulator does not support speech
recognition so you need to test this functionality on an actual device. The
source code is attached, so you can check if you have everything in the right place.
Of course, your own apps may implement speech recognition as part of other
processing, but this tutorial should have equipped you with the essentials of
supporting speech input.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Advertisement

Difficulty: Suggested Tuts+ Course


Intermediate
Length:
Medium
Categories:

Android SDK Mobile Development

Translations Available:

Tuts+ tutorials are translated by our community


members. If you'd like to translate this post into
Building Android Apps In C# With $15
another language, let us know! Xamarin
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Download Attachment
Related Tutorials

Use Text-to-Speech on Android to


Read Out Incoming Messages
Code
About Sue Smith
I'm a technical writer and sometimes
developer, based in the UK. Producing
Build A Custom Launcher on Android
educational material and documentation, I
Code
cover mobile, Web and software development
topics.

Google Play Game Services:


Leaderboards
Code

Jobs

WordPress Developer
at WebDevStudios in Los Angeles, CA,
USA

Front-End WordPress Designer


Advertisement
at WebDevStudios in Los Angeles, CA,
USA
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Envato Market Item

34 Comments Mobiletuts+

Sort by Best

Join the discussion

Liam 2 years ago


Hi Sue,
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Thanks so much for the tutorial I learned a lot. I was wondering if you can show us a way to get rid of the g
launcher when having the speech to text pop up. In other words, can you show us a way so that when we
button to speech recognize a window doesn't pop up?

Thanks a ton!!
6 Reply Share

Krunal Sabnis 7 months ago


Hi Sue,

Thanks for tutorial, very well explained.

But What about, Listen -> Repeat -> Listen again? What I am trying to achieve is after app listens user, It
speak back asking for Yes/No Confirmation and based on that further processing should happen. When I
again (in this case listenToSpeech(), It runs the code without waiting for Speaker to let finish speaking. ca
please point me in right direction?
2 Reply Share

Farish 2 years ago


Thanks for the great tutorial. very easy to follow for an absolute beginner like me.
1 Reply Share

android uygulamalar 2 years ago


Superb, what a blog it is! This web site presents helpful facts to us, keep it up.
1 Reply Share

Sue 9 months ago


The source code for this tutorial is now also hosted on GitHub: https://github.com/SueSmith/an...
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Feel free to use and/ or contribute to it there!
Reply Share

harish mehta a year ago


i got some error running on emulator:

Failed to install SpeechRepeatActivity.apk on device 'emulator-5554': timeout

[2013-09-02 19:36:08 - SpeechRepeatActivity] Launch canceled!


Reply Share

Sweta Attri > harish mehta 4 months ago


Please start the emulator again.
Reply Share

Siddhu Vydyabhushana a year ago


nice and excellent ...
Reply Share

akira32 a year ago


How do I speech recognition with given words? I only compare the result with my given words.
Reply Share

ABABABABABAB 2 years ago


Awesome!!! Thank yuo so much!!!!!!!!!!!!!!
Reply Share

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
BitX 2 years ago
Thanks Sue!.

Is very Useful
Reply Share

medalla 2 years ago


Awesome! Great job!
Reply Share

WoW 2 years ago


resultCode = 0 (is not OK) ? What can I do ?
Reply Share

WoW 2 years ago


Why I cannot get the interface to speech to app. When I click on "Speak now" just show very fast the runn
dialog and after that TTS engine show its dialog with message: Connection Problem.
Reply Share

mirza 2 years ago


thanks for the tutorial ..

anyway, may i ask something?


can the speech to text only take 1 sugested word?

thanks before
Reply Share

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Maximiliano 2 years ago
Hello friends,

When I reach the past part of Step 2, this is: Create a new file in res/layout named word.xmland then e
following code:

I get the following error: [2012-10-22 00:47:02 - testspeech] Error in an XML file: aborting build.

Can someone tell me a suggestion?

Thank you.
Reply Share

Mirza 2 years ago


thanks before

i have try the source code, but when i have speech, before the list of word show, the app suddenly force c

can you help me?

sorry for bad english :)


Reply Share

Anonimous 2 years ago


Thanks a lot for this tutorial, easy to follow and be successful :)
Reply Share

Said Tahsin Dane 2 years ago


What an article. Thank you. Thats what I am talking about :)
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Reply Share

wasana 2 years ago


Compilations was completed. R.java has been generated. But there is error 'R cannot be resolved to a va
SpeechRepeatActivity.java.

Could you please give me some suggestion?


Reply Share

wasana > wasana 2 years ago


Done. A package name in manifest file did not correspond to .java.

However, I have encountered another problem. An installed .apk cannot be launched in an actual d
Reply Share

Aman 2 years ago


Hello Sue,
I am keen to know about android app development using Adobe Flash CS5.5 , but I am not able to find som
content regarding its tutorials. Can you please help.
Reply Share

Sue Smith (author) > Aman 2 years ago


Hi Aman
I'm afraid that isn't something I know about. In general I would recommend learning Android develo
using the official tools within the Eclipse IDE for the best results.
Reply Share

aditya 2 years ago


open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
app build whitout any error but when i run the app on emulate the button is disabled and giving message v
recognition not supported. i m using android sdk 2.2. please help me.
Reply Share

Sue Smith (author) > aditya 2 years ago


Hi Aditya
This is a case where you need to run your app on an actual Android device, as the emulator does
voice input.
Reply Share

Pritesh Desai 2 years ago


This app requires persistent net connection, right?
Reply Share

Sue Smith (author) > Pritesh Desai 2 years ago


Hi Pritesh
Yes, the voice recognition process involves retrieving data from Google.
Sue
Reply Share

Vamsi > Sue Smith (author) a year ago


If your android version is >4.0 then you need not have a persistent net connection. From 4.
built in support for voice recog.
Reply Share

Anoop 2 years ago


i did all the steps and got the output, but the user selection is not played in voice. ........... please help!!!!!!!
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Reply Share

Sue Smith (author) 2 years ago


Hi Pieter

You shouldn't attempt to run the app until the steps are completed, I've only included a screen shot so tha
see what the code is building. The error is because you haven't added the onInit method yet, which you do

Sue
Reply Share

Pieter 2 years ago


At step 4 you seem to be able to already run the app but in my case I get an error:

import android.app.Activity;
import android.content.DialogInterface;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.view.View.OnClickListener;

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.TextView;
see more

Reply Share

Anum Gul > Pieter a year ago


can u help me in speech recongnition through camera
Reply Share

hahaha ass > Pieter 2 years ago


u r an ass
Reply Share

Anum Gul > hahaha ass a year ago


coding for speech recongnition through camera
Reply Share

Subscribe d Add Disqus to your site Privacy

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Advertisement

18,726 Tutorials 447 Video Courses


Teaching skills to millions worldwide.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Follow Us Email Newsletters

Get Tuts+ updates, news, surveys &



offers.

Help and Support Email Address

FAQ
Subscribe
Terms of Use
Contact Support Privacy Policy
About Tuts+
Advertise
Teach at Tuts+

Custom digital services like logo design, WordPress installation, video


production and more.
Check out Envato Studio

Add more features to your website such as user profiles, payment


gateways, image galleries and more.
Browse WordPress Plugins

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
2014 Envato Pty Ltd. Trademarks and brands are the property of their respective
owners.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com

Вам также может понравиться