Alex Rivera | Logout

Android not acknowledging TTS Engine

Asked 2012-02-26T03:44:53.080
11

I am developing a very simple app in here. It's for my Cerebral Palsy daughter. It's just a big YES and NO buttons, so she can press them when requested.

Well... I am using SVOX Classic TTS Engine.

Everything was running smoothly until my tablet upgraded to ICS. Now, everytime I run the app, it opens the Market asking for me to install TTS. I hit "back" and then, my app speaks. This is VERY annoying.

Here is what Google API says:

*A successful check will be marked by a CHECK_VOICE_DATA_PASS result code, indicating this device is ready to speak, after the creation of our TextToSpeech object. If not, we need to let the user know to install the data that's required for the device to become a multi-lingual talking machine! Downloading and installing the data is accomplished by firing off the ACTION_INSTALL_TTS_DATA intent, which will take the user to Android Market, and will let her/him initiate the download. Installation of the data will happen automatically once the download completes. Here is an example of what your implementation of onActivityResult() would look like:*

Here is my code:

public class yesOunoActivity extends Activity implements OnInitListener{
ImageView yes;
ImageView no;
public TextToSpeech tts;
private int MY_DATA_CHECK_CODE = 0;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

    tts = new TextToSpeech(this, this);

    setContentView(R.layout.yesorno);

    yes = (ImageView) findViewById(R.id.yes);
    no = (ImageView) findViewById(R.id.no);


    yes.setClickable(true); 
    yes.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent arg1) {

             if (arg1.getAction() == android.view.Moti
Edit
Report

1 Answer

1

I had this trouble on my application as well: TTS works in 2.3, but when I tried 4.0, it had the same symptoms as your problem (which I just found now while searching for a solution). The engine would work if you force-closed the application through Settings and started it again but just "backing out" and going back made the TTS engine in ICS not bind.

I tried setting the TTS object (mTts) to null after running mTts.shutdown(). When I started the application again after backing out, I got a null error on my mTts.speak() line.

At least for ICS, something is not letting go of the TTS engine. My solution (for now) is that I have made my TTS object static:

// in Activity
private static TextToSpeech mTts;
.
.
.
// in onCreate()
mTts = new TextToSpeech(this, this);
.
.
.
// in onDestroy()
if (mTts != null) {
   mTts.stop();
   mTts.shutdown();
   mTts = null;
}

I was already only using one TTS object for the application so I don't think there are too many downsides to this approach.

answered 2012-07-10T22:25:52.603

Your Answer