Android for easy Voice reading

Source: Internet
Author: User

Voice reading, which is a good feature that can achieve some of the customer's special requirements. It takes just a few simple pieces of code to make the idea function on Android.

The use of speech-reading in Android only requires the use of such Texttospeech, which implements a lot of speech-related functions, which must be set for the language, the support Language list is located in the local class of the Java.util class, as follows:

Screen problems, display insufficient, you can go to the SDK to view. Although the support of a number of ideas list, but seemingly android built-in voice reading language is not much, is not in the future to write the system in the time or how, this does not know why, at present I only test the Chinese and Chinese. Chinese is feasible, Chinese failed. OK, nonsense not much to say, on all implementation code:

Code highlighting produced by Actipro Codehighlighter (freeware) http://www.CodeHighlighter.com/-->package Com.terry;Import Java.util.locale;import Android.app.activity;import android.os.bundle;import Android.speech.tts.texttospeech;import Android.speech.tts.texttospeech.oninitlistener;import Android.util.Log; Import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.EditText; Public classSpeechactivity extends Activity {PrivateTexttospeech Mspeech; PrivateButton btn; PrivateEditText Medittext; /** Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.main); BTN=(Button) Findviewbyid (R.ID.BUTTON01); Medittext=(EditText) Findviewbyid (r.id.edittext01); Btn.setenabled (false); Mspeech=NewTexttospeech ( This,NewOninitlistener () {@Override Public voidOnInit (intstatus) {                //TODO auto-generated Method Stub                if(Status = =texttospeech.success) {intresult =mspeech.setlanguage (locale.english); 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);        }                }            }        }); Btn.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method StubMspeech.speak (Medittext.gettext (). toString (), Texttospeech.queue_flush,NULL);    }        }); } @Overrideprotected voidOnDestroy () {//TODO auto-generated Method Stub        if(Mspeech! =NULL) {mspeech.stop ();        Mspeech.shutdown ();    } Super.ondestroy (); }}

Android for easy Voice reading

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.