TTS 未在服务中停止:停止失败:未绑定到 TTS 引擎
TTS not stop in Service: stop failed: not bound to TTS engine
我的 TTS 在服务中没有停止并说了两次。
在 logcat 中,错误是 "stop failed: not bound to TTS engine"
我被困在这里,为什么 TTS 没有停止。我要在这里做什么才能在说话时阻止它。
这是我的代码
public class Speaker extends Service implements TextToSpeech.OnInitListener {
public static TextToSpeech mtts;
String speech = "";
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
}
@Override
public void onStart(Intent intent, int startid) {
speech=intent.getExtras().getString("speech");
mtts = new TextToSpeech(getApplicationContext(), this);
}
@Override
public void onDestroy() {
if (mtts != null) {
Log.e("Destroy", "Service");
mtts.stop();
mtts.shutdown();
}
super.onDestroy();
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS)
mtts.speak(speech, TextToSpeech.QUEUE_ADD, null);
}
Log.e("onInit ends", "Service");
}
}
}
一个原因是,当 phone 呼叫传入时,此时您的广播接收器将一次又一次地呼叫此 activity,除非您选择 phone
如果你想在让它说一次之后停止这个服务。
停止服务的代码。
Intent in = new Intent(this, Speaker.class);
stopService(in);
在 onDestroy() 或 onStart() 方法中使用此代码。
为什么要使用 TTS 服务?您可以使用任何 activity 或 class 等
我的 TTS 在服务中没有停止并说了两次。 在 logcat 中,错误是 "stop failed: not bound to TTS engine" 我被困在这里,为什么 TTS 没有停止。我要在这里做什么才能在说话时阻止它。 这是我的代码
public class Speaker extends Service implements TextToSpeech.OnInitListener {
public static TextToSpeech mtts;
String speech = "";
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
}
@Override
public void onStart(Intent intent, int startid) {
speech=intent.getExtras().getString("speech");
mtts = new TextToSpeech(getApplicationContext(), this);
}
@Override
public void onDestroy() {
if (mtts != null) {
Log.e("Destroy", "Service");
mtts.stop();
mtts.shutdown();
}
super.onDestroy();
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS)
mtts.speak(speech, TextToSpeech.QUEUE_ADD, null);
}
Log.e("onInit ends", "Service");
}
}
}
一个原因是,当 phone 呼叫传入时,此时您的广播接收器将一次又一次地呼叫此 activity,除非您选择 phone 如果你想在让它说一次之后停止这个服务。 停止服务的代码。
Intent in = new Intent(this, Speaker.class);
stopService(in);
在 onDestroy() 或 onStart() 方法中使用此代码。 为什么要使用 TTS 服务?您可以使用任何 activity 或 class 等