java - Android TextToSpeech engine not bound, but not on first run -


i trying write super simple app texttospeech, when button clicked.

i ran app, , on first time, tts worked! (i heard speak). when ran again (and many more time), didn't speak, though code stayed same. tell me how work out?

i guess i'm missing fundamental how tts works, i'd appreciate if explain dummy.
thank much, julius

here's layout file:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:gravity="center">      <linearlayout         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:orientation="vertical" />      <button         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:onclick="test1"         android:text="test" />      <button         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="open local db" />      <button         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="open global db" /> </linearlayout> 

the mainactivity code:

public class mainactivity extends activity {//0      public void test1(view myview) {         int e = 1;         system.out.println("starting test.....");         //step s1=new step();         toast.maketext(getapplicationcontext(), "aaaaaaa", toast.length_short).show();         speaker.speak("aaaaaaaaaa", texttospeech.queue_flush, null);         speaker.stop();         speaker.shutdown();     }      texttospeech speaker;      @override     protected void oncreate(bundle savedinstancestate) {//1         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         speaker = new texttospeech(getapplicationcontext(), new texttospeech.oninitlistener() {//2             @override             public void oninit(int status) {//3                 if (status == texttospeech.success) system.out.println("success!!!");                 if (status != texttospeech.error) {//4                     speaker.setlanguage(locale.uk);                 }//4                 else {                     system.out.println("speak err");                 }             }//3         }//2         );     }//1      @override     public void onpause() {         if (speaker != null) {             speaker.stop();             speaker.shutdown();         }         super.onpause();     }//1*/ }//0 

and (thanks reading until now...) here's logcat:

05-11 14:57:35.149 30221 30221   art com.mycompany.myapp                      late-enabling -xcheck:jni 05-11 14:57:35.460 30221 30221   texttospeech com.mycompany.myapp             sucessfully bound com.google.android.tts 05-11 14:57:35.470 30221 30246 d   openglrenderer com.mycompany.myapp           use egl_swap_behavior_preserved: true 05-11 14:57:35.535 30221 30221 d   atlas com.mycompany.myapp                    validating map... 05-11 14:57:35.639 30221 30246   adreno-egl com.mycompany.myapp               <qegldrvapi_eglinitialize:379>: qualcomm build: 01/14/15, ab0075f, id3510ff6dc 05-11 14:57:35.641 30221 30246   openglrenderer com.mycompany.myapp           initialized egl, version 1.4 05-11 14:57:35.666 30221 30246 d   openglrenderer com.mycompany.myapp           enabling debug mode 0 05-11 14:57:35.907 30221 30221   texttospeech com.mycompany.myapp             connected componentinfo{com.google.android.tts/com.google.android.tts.service.googlettsservice} 05-11 14:57:35.918 30221 30268   texttospeech com.mycompany.myapp             set connection componentinfo{com.google.android.tts/com.google.android.tts.service.googlettsservice} 05-11 14:57:35.919 30221 30221   system.out com.mycompany.myapp               success!!! 05-11 14:57:36.917 30221 30221   system.out com.mycompany.myapp               starting test..... 05-11 14:57:36.985 30221 30246 v   renderscript com.mycompany.myapp             application requested cpu execution 05-11 14:57:37.005 30221 30246 v   renderscript com.mycompany.myapp             0xb4819e00 launching thread(s), cpus 4 05-11 14:57:38.465 30221 30221 w   texttospeech com.mycompany.myapp             stop failed: not bound tts engine 05-11 14:57:38.465 30221 30221 w   texttospeech com.mycompany.myapp             shutdown failed: not bound tts engine 

thanks again

public void shutdown ()
releases resources used texttospeech engine. practice instance call method in ondestroy() method of activity texttospeech engine can cleanly stopped.

reference: http://developer.android.com/reference/android/speech/tts/texttospeech.html#shutdown()

for reason tts works first time, release resources of texttospeech.

you should remove speaker.shutdown(); test1 , put in ondestroy:

@override protected void ondestroy() {     speaker.shutdown();     super.ondestroy(); } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -