Android Voice reading function demo implementation

Source: Internet
Author: User

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

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.