[英]Android TTS sound Leaked Service Connection and speak deprecated
我在我的课程中使用android tts只是说一条消息,例如:问题:服务连接泄漏
public class WorkTimerNotification extends ActionBarActivity implements TextToSpeech.OnInitListener {
TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work_timer_notification);
//line1
tts = new TextToSpeech(this,this);
@Override
public void onInit(int status) {
//line2
tts.setLanguage(Locale.US);
//line3
tts.speak("Text to say aloud", TextToSpeech.QUEUE_ADD, null);
tts.shutdown();
}
@Override
protected void onDestroy() {
super.onDestroy();
tts.shutdown();
}
第1行,我使用以下logcat泄漏了serviceConnection:
WorkTimerNotification has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@41aee290 that was originally bound here
android.app.ServiceConnectionLeaked
我按此按钮,由于某种原因,它仍然返回哈希表。 我不知道为什么...
int speak(CharSequence, int, Bundle, String)
我也尝试过:但是它也不起作用。
@Override
protected void onDestroy() {
//Close the Text to Speech Library
if(tts!= null) {
tts.stop();
ttsRest.shutdown();
Log.d(TAG, "TTS Destroyed");
}
super.onDestroy();
}
你不能打电话speak
,直到之后onInit
被调用,将您speak
的代码onInit
public class WorkTimerNotification extends ActionBarActivity implements TextToSpeech.OnInitListener {
TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work_timer_notification);
//line1
}
@Override
public void onInit(int status) {
//line2
tts.setLanguage(Locale.US);
//line3
tts.speak("Text to say aloud", TextToSpeech.QUEUE_ADD, null);
}
@Override
protected void onStart()
{
super.onStart();
tts = new TextToSpeech(this,this);
}
@Override
protected void onStop()
{
super.onStop();
tts.shutdown();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.