android - 停止/关机失败 : not bound to TTS engine

标签 android text-to-speech

我有一个使用 TTS 的 Android Activity ,但是当我退出它时,在 Logcat 中出现泄漏的服务连接错误。在泄露的服务错误上方,我得到一条声明:

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

我的 onStop 和 onDestroy 看起来像这样: 编辑代码:

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

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

我在用户按下按钮时触发了 TTS(TTS 工作正常,我只是想修复服务连接错误)

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

这是我的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 工作正常,我可以看到引擎在 logcat 中被调用,但由于某些原因 tts.stop()tts.shutdown() 不是绑定(bind)到同一个引擎。

EDIT2:看来我不止一次连接到 TTS 引擎和服务。每次我希望 TTS 在 Activity 中说出文本时,都会与 TTS 引擎和 TTS 服务建立另一个连接。

文本更改时我的 TTS 代码如下所示:

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 由上面的 v == speakButton 代码触发。

最佳答案

不要两次调用 tts.shutdown(),在 onDestroy() 中就足够了。

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

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

关于android - 停止/关机失败 : not bound to TTS engine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25426754/

相关文章:

android - 在 Android 中的布局中屏蔽图像

python - Pyttsx,我无法更改代码中的性别...,我做错了什么?

python - 如何解决python中的属性错误

html - Firefox 和语音合成 API

android - React Native 找不到项目的匹配配置(仅限构建)

android - 相机预览始终返回 320x240 位图

java - 无法为 GridView 布局设置背景颜色

java - 尝试在 MainActivity 之外膨胀 PopupWindow

android - 如何在 Android 上等待 TextToSpeech 初始化

javascript - 如何将 TextToSpeech.talk ("hi' ) 操作添加到按钮