Android TTS 声音泄漏服务连接和说话已弃用
Android TTS sound Leaked Service Connection and speak deprecated
我在我的 class 中使用 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 行我得到泄漏的 serviceConnection logcat:
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();
}
在调用 onInit
之前,您不能调用 speak
,将您的 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();
}
我在我的 class 中使用 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 行我得到泄漏的 serviceConnection logcat:
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();
}
在调用 onInit
之前,您不能调用 speak
,将您的 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();
}