Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop / shutdown failed: not bound to TTS engine

I have an android activity that uses TTS but when I exit it get a leaked Service Connection error in Logcat. Above the leaked Service error I get a statement that:

stop failed: not bound to TTS engine
shutdown failed: not bound to TTS engine

My onStop and onDestroy look like this: EDIT Code:

@Override
public void onStop() {
    if (tts != null) {
    tts.stop();
    }
    super.onStop();
}

@Override
public void onDestroy() {
    if (tts != null) {
        tts.shutdown();
    }
    super.onDestroy();
}

I trigger the TTS when the user pushes a button (TTS does work ok, I am just trying to fix the service connection error)

if (v == speakButton && ttscrashprotect == 1) {   
    String text = inputText.getText().toString();
    if (text != null && text.length() > 0) {
        tts.speak(text, TextToSpeech.QUEUE_ADD, null);
    }

This is my onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_DATA_CHECK_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            //sucess with TTS create it
            tts = new TextToSpeech(this, this);
        }
        else {
            //missing TTS so install it
            Intent installIntent = new Intent();
            installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
        }
    }

TTS is working fine and I can see the engine being called in logcat, but for some reason the tts.stop() and tts.shutdown() aren't bound to the same engine.

EDIT2: It would seem I am connecting to the TTS engine and service more than one time. Each time the text that I want TTS to say within the activity then another connection is made to the TTS engine and TTS service.

My TTS code when the text changes looks like this:

if (v==nextButton && progressL1<100) {
    Video.setVisibility(View.INVISIBLE); //hide the video view

    progressL1= progressL1 + 10;
    //increase progress by 10 and then load the new files
    //load the TTS text data from Asset folder progressL1 txt file
    Advanced.this.loadDataFromAsset(progressL1);
    //try some tts stuff here
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

TTS is triggered from the v == speakButton code above.

like image 372
andy Avatar asked Oct 31 '22 18:10

andy


1 Answers

Do not call tts.shutdown() twice, just in onDestroy() will be sufficient.

@Override
public void onStop() {
    if (tts != null) {
        tts.stop();
    }
    super.onStop();
}

@Override
public void onDestroy() {
    if (tts != null) {
        tts.shutdown();
    }
    super.onDestroy();
}
like image 105
Alexis Pigeon Avatar answered Nov 15 '22 03:11

Alexis Pigeon