android can also be implemented to read the input text, using Texttospeech, but currently only supports 5 languages: english french german italian and spanish. (I'm sorry, no Chinese), for Android system requirements for Android 1.6 (API8) above:
public class Speechtestactivity extends Activity {
/**texttospeech Object */
Private Texttospeech Mtext2speech;
/** OK button */
Private Button mBtn;
/** Text Input Box */
Private EditText MEdt;
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Findviewsbyid ();
Initlisteners ();
MBtn = (Button) Findviewbyid (R.ID.TEST_BTN);
MEdt = (EditText) Findviewbyid (R.id.test_edt);
Mbtn.setenabled (FALSE);
}
private void Initlisteners () {
Mtext2speech = new Texttospeech (This, new Oninitlistener () {
@Override
public void onInit (int status) {
if (status = = texttospeech.success) {/** If the Mount TTS succeeds */
int result = Mtext2speech.setlanguage (locale.english),/** has Locale.chinese, but does not support Chinese */
The IF (result = = texttospeech.lang_missing_data/** represents the data loss of the language. */
|| result = = texttospeech.lang_not_supported) {/** language not supported */
Toast.maketext (Speechtestactivity.this, "I can't say", Toast.length_short). Show ();
} else {
Mbtn.setenabled (TRUE);
Mtext2speech.speak ("I Miss You", Texttospeech.queue_flush,
NULL);
}
}
}
});
Mbtn.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Mtext2speech.speak (Medt.gettext (). toString (),
Texttospeech.queue_flush, NULL);
}
});
}
private void Findviewsbyid () {
MBtn = (Button) Findviewbyid (R.ID.TEST_BTN);
MEdt = (EditText) Findviewbyid (R.id.test_edt);
}
@Override
protected void OnDestroy () {
if (Mtext2speech! = null) {
Mtext2speech.stop ();
Mtext2speech.shutdown ();
}
Super.ondestroy ();
}
}
Simple use of Texttospeech in Android