Android Combat--small demo (the implementation of the speech synthesis TTS of the Java keyword Learning)

Source: Internet
Author: User

Following the questions discussed in the previous section, TTS speech synthesis is used in this demo, and we introduce a small example of the same principle below

Looking at the layout file is simple:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "  android:orientation=" vertical "  android:layout_width=" fill_parent "  android:layout_height=" Fill_parent "  android:background=" @android: Color/white "   >  <textview      android:layout_width= "Fill_parent"     android:layout_height= "wrap_content"     android:text= "@string/hello"  />  < EditText     android:id= "@+id/edittext01"     android:layout_width= "wrap_content"     android:layout_height = "Wrap_content"    android:hint= "Input something to speak ..."  >  </EditText>  < ImageButton     android:id= "@+id/imagebutton01"     android:layout_width= "wrap_content"     android:layout_ height= "Wrap_content"    android:src= "@android:d rawable/ic_btn_speak_now"  >  </imagebutton ></LinearLayout>


Here is the activity:

Package Irdc.ex07_18;import Java.util.locale;import Android.app.activity;import android.os.bundle;import Android.speech.tts.texttospeech;import Android.util.log;import Android.view.view;import Android.widget.imagebutton;import Android.widget.edittext;public class Ex07_18 extends activity{public static String  TAG = "Ex07_18_debug";  Private Texttospeech TTS;  Private EditText EditText01;  Private ImageButton ImageButton01; /** called when the activity is first created.    */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);    Setcontentview (R.layout.main);    /* Incoming context and Oninitlistener */TTS = new Texttospeech (this, ttsinitlistener);    EditText01 = (EditText) This.findviewbyid (r.id.edittext01);    ImageButton01 = (ImageButton) This.findviewbyid (R.ID.IMAGEBUTTON01);      Imagebutton01.setonclicklistener (New Imagebutton.onclicklistener () {@Override public void OnClick (View v) {//TODO auto-generated method Stub if (Edittext01.gettext (). Length () > 0) {/* incoming string to say */Tts.speak (Edittext01.gett        Ext (). toString (), texttospeech.queue_flush, NULL);        } else {/* No input String */Tts.speak ("Nothing to say", Texttospeech.queue_flush, NULL);  }      }    }); } private Texttospeech.oninitlistener Ttsinitlistener = new Texttospeech.oninitlistener () {@Override public void OnInit (int status) {///TODO auto-generated Method Stub/* Use US time zone currently does not support Chinese */locale loc = new locale ("US"      , "", ""); /* Check if the input time zone is supported */if (tts.islanguageavailable (loc) = = texttospeech.lang_available) {/* Set language */TT      S.setlanguage (Loc);      } tts.setonutterancecompletedlistener (Ttsutterancecompletedlistener);    LOG.I (TAG, "Texttospeech.oninitlistener");  }  }; Private Texttospeech.onutterancecompletedlistener Ttsutterancecompletedlistener = new  Texttospeech.onutterancecompletedlistener () {  @Override public void onutterancecompleted (String utteranceid) {//TODO auto-generated method stub Log.    I (TAG, "Texttospeech.onutterancecompletedlistener");  }  }; @Override protected void OnDestroy () {//TODO auto-generated method Stub/* Releases Texttospeech resources */Tts.shutdown (    );    LOG.I (TAG, "Tts.shutdown");  Super.ondestroy (); }}


To run an instance effect:

TTS understands, specifically, where you can use it to make your application more colorful, and see your personal creativity.

SOURCE Download: http://download.csdn.net/detail/yayun0516/8710403

Application:

http://openbox.mobilem.360.cn/index/d/sid/2966005

http://android.myapp.com/myapp/detail.htm?apkName=com.yayun.gitlearning

Welcome to download, there are problems and more communication! ( like, please pay attention to me, thank you!) )

Android Combat--small demo (the implementation of the speech synthesis TTS of the Java keyword Learning)

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.