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:
Popularity: 26% [?]
Can i take a one small pic from your blog?
Elcorin
The article on antibiotics are very good.
Hi! I followed your tutorial but i don’t hear any voice reading.
Send me an email and tell me everything that you did and I will help you out.
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.
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.
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..
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.
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
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.
I had to download the TTS library on the G1 but once I did the code worked which is awesome.
Thanks