我有一个使用TTS的android活动,但是当我退出它时,它会在Logcat中得到一个泄漏的Service连接错误。在泄露的服务错误之上,我得到一条语句:
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()并不绑定到同一个引擎。
EDIT2:我似乎不止一次连接到TTS引擎和服务。每次我希望TTS在活动中说的文本,就会有另一个连接到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代码触发的。
发布于 2014-08-21 13:54:06
不要两次调用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();
}https://stackoverflow.com/questions/25426754
复制相似问题