Simple text speech reading function implementation
The main implementation of this function is a class, is Texttospeech, nonsense is not less, directly on the code. Generally speaking, the rhythm of the phrase pauses is not very good.
The interface is simple, a button, a EditView, no code.
public class Activityresumptionarticle extends baseactivity{
Private Texttospeech Mspeech = null;
Private Button btn = null;
Private Edittextview ev = NULL;
protected void OnCreate (Bundle arg0) {
Super.oncreate (arg0);
Setcontentview (r.layout.activity_resumption_article);
Test read aloud function
BTN = (Button) Findviewbyid (r.id.but);
ev = (editview) Findviewbyid (R.id.ev);
Mspeech = new Texttospeech (This, new Oninitlistener () {
@Override
public void onInit (int status) {
if (status = = Texttospeech.success) {
The following code is the main, set the language, if it is in English, use Locale.english
int result = Mspeech.setlanguage (Locale.china);
if (result = = Texttospeech.lang_missing_data
|| result = = texttospeech.lang_not_supported) {
LOG.E ("Lanagetag", "not use");
} else {
Btn.setenabled (TRUE);
Mspeech.speak ("I Love You", Texttospeech.queue_flush,
NULL);
}
}
}
});
//Progress listener, a bit rough, but enough, remember after done will Mpeech shutdown
mspeech.setonutteranceprogresslistener (new Utteranceprogresslistener () {
@Override
public void OnStart (String Utteranceid) {
}
@Override
public void OnError (String utteranceid) {
}
&NBSP
@Override
public void Ondone (String utteranceid) {
mspeech.shutdown ();
}
});
Btn.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Start reading
Mspeech.speak (Ev.gettext (). toString (),
Texttospeech.queue_flush, NULL);
}
});
}
}