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.

AndroidSpeech.java
package com.exercise.AndroidSpeech;

import android.app.Activity;
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. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

myTTS = new TextToSpeech(this, this);
}

@Override
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);
}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
myTTS.shutdown();
}
}




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."

{ 0 comments... read them below or add one }

Post a Comment