Wednesday, September 23, 2009

AndroidSpeech: Android can speech!

A new feature, Text-To-Speech (TTS), have been introduced in version 1.6 of the Android platform. Also known as 'speech synthesis', TTS enables Android device to 'speak' text of different languages.

it's a very simple code to make Android speech. It can speech only.

Create a Android Application, with Target platform 1.6, API Level 4. Modify the code as following.
package com.exercise.AndroidSpeech;

import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;

public class AndroidSpeech extends Activity implements OnInitListener{

TextToSpeech myTTS;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

myTTS = new TextToSpeech(this, this);

public void onInit(int status) {
// TODO Auto-generated method stub

String myText1 = "Hello Android!";
String myText2 = "I can speech.";
myTTS.speak(myText1, TextToSpeech.QUEUE_FLUSH, null);
myTTS.speak(myText2, TextToSpeech.QUEUE_ADD, null);

protected void onDestroy() {
// TODO Auto-generated method stub

For more details of Android Text-To-Speech, refer to:
Android Developers Blog: An introduction to Text-To-Speech in Android: "We've introduced a new feature in version 1.6 of the Android platform: Text-To-Speech (TTS). Also known as 'speech synthesis', TTS enables your Android device to 'speak' text of different languages."

No comments: