Dedicated to satisfying your computer needs

twitter button digg button
Subscribe to Blog
Subscribe via email Subscribe via RSS Subscribe via Comments

Text to Speech for the Google OS, Android (Updated)

Posted by Michael Washington On April - 10 - 2009

Text to Speech in Android

Version of android executed in: 1.6rc2 in Windows


TOOLS we used:

Eclipse and Android library 1.6rc2

How it works:

1. In android 1.6rc2 the text to speech library is built in called android.speech.tts, here is link for the information http://developer.android.com/reference/android/speech/tts/TextToSpeech.html

2. Here is the code

package com.android;

import java.util.Locale;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;

public class TtS extends Activity implements OnInitListener{
/** Called when the activity is first created. */
private TextToSpeech mTts;

int MY_DATA_CHECK_CODE = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
mTts = new TextToSpeech(this,this);

}

@Override
public void onInit(int arg0) {
// TODO Auto-generated method stub
String myText1 = “Did you sleep well?”;
String myText2 = “I hope so, because it’s time to wake up.”;
mTts.setLanguage(Locale.US);
mTts.speak(myText1, TextToSpeech.QUEUE_FLUSH, null);
mTts.speak(myText2, TextToSpeech.QUEUE_ADD, null);
}

}

3. To make it even easier you can use you can download the code and open as an existing project. Click here to download.

References:

  1. http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html

Bookmark and Share

Popularity: 53% [?]

Related Posts

11 Responses to “Text to Speech for the Google OS, Android (Updated)”

  1. Elcorin says:

    Can i take a one small pic from your blog?
    Elcorin

  2. The article on antibiotics are very good.

  3. pw says:

    Hi! I followed your tutorial but i don’t hear any voice reading.

  4. Michael Washington says:

    Send me an email and tell me everything that you did and I will help you out.

  5. pw says:

    Does android sdk 1.5 support speech? Cos it seem to b prob wif my comp. It also doesn’t wrk when i use sdk 1.1.

  6. Michael Washington says:

    The android SDK 1.5 and SDK 1.1 do not support speech by themselves. You have to use an external library for text to speech like the one I have listed.

  7. aLİ says:

    hi, i did everything you told above, but i am not able to hear something, i use android sdk 1.6 rc1, can it be a problem?
    Thx Michael..

  8. Send an email to me at michael.p.washington@compscistuff.com and I can help you out. This tutorial is for 1.5, what I will try to do is update this one for android 1.6 and 2.0.

  9. Petar K says:

    If you could update your code to work for 1.6 or 2.0 that would be great as I am also having trouble implementing TTS for 1.6

    Thanks

  10. I have put a updated text to speech article up here and I have tested out the code. It converts the Text into Speech alright. Let me know how it works out for y’all.

  11. Petar K says:

    I had to download the TTS library on the G1 but once I did the code worked which is awesome.

    Thanks

Leave a Reply