java - speak failed:not bound to tts engine -
issue : speak failed:not bound tts engine
i implementing texttospeech
functionality. getting exception speak failed: not bound tts engine
. implementing async task
it. async task
reading mail
. , want convert mail body speech
.
package com.example.trynot; import android.os.bundle; import android.app.activity; import android.view.menu; import java.util.locale; import com.example.trynot.mainactivity.readmailsample; import android.app.activity; import android.os.bundle; import android.speech.tts.texttospeech; import android.util.log; import android.view.view; import android.widget.button; import android.widget.edittext; public class notify extends activity implements texttospeech.oninitlistener { /** called when activity first created. */ public texttospeech tts = new texttospeech(mainactivity.c, notify.this); public notify() { system.out.println("inside constructor"); speakout(); } @override public void ondestroy() { // don't forget shutdown tts! if (tts != null) { tts.stop(); tts.shutdown(); } super.ondestroy(); } @override public void oninit(int status) { system.out.println("inside init"); if (status == texttospeech.success) { int result = tts.setlanguage(locale.us); tts.speak(mainactivity.readmailsample.command, texttospeech.queue_flush, null); if (result == texttospeech.lang_missing_data || result == texttospeech.lang_not_supported) { log.e("tts", "this language not supported"); } else { speakout(); } } else { log.e("tts", "initilization failed!"); } } private void speakout() { system.out.println("inside speak out"); tts.speak(mainactivity.readmailsample.command, texttospeech.queue_flush, null); } }
you should move instatiation of tts engine instance oncreate, line:
public texttospeech tts = new texttospeech(mainactivity.c, notify.this);
change to:
public texttospeech tts;
and add inside oncreate
:
tts = new texttospeech(mainactivity.c, notify.this);
and - whats important - not use constructor in activity derived classes:
public notify() { system.out.println("inside constructor"); speakout(); }
should oncreate:
@override protected void oncreate (bundle savedinstancestate) { super.oncreate(savedinstancestate); //speakout(); // here tts not yet initialized, call in oninit on success //tts = new texttospeech(mainactivity.c, notify.this); // whats mainactivity.c? tts = new texttospeech(this, this); }
Comments
Post a Comment