TextToSpeech当按下后退按钮时,我正试图停止。但即使我关闭我的应用程序,讲话也不会停止。仅当我清除缓存时,语音才会停止。我该如何解决这个问题?请帮助我理解。
private boolean mShouldSpeak = true;\nTextToSpeech tts;\n @Override\nprotected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_cat);\n\n tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {\n @Override\n public void onInit(int status) {\n if (status == TextToSpeech.SUCCESS) {\n tts.setEngineByPackageName(enginePackageName);\n tts.setLanguage(Locale.getDefault());\n tts.setPitch(0);\n tts.setSpeechRate(1);\n speak();\n }\n }\n });\n}\n private void speak() {\n\n if (mShouldSpeak == true)\n {\n tts.speak("\xd0\x90\xd0\xb2\xd1\x82\xd0\xbe\xd1\x80: " +getResources().getString(R.string.catAuthor), TextToSpeech.QUEUE_ADD, null);\n tts.playSilence(1000, TextToSpeech.QUEUE_ADD, null);\n tts.speak(getResources().getString(R.string.catName), TextToSpeech.QUEUE_ADD, null);\n tts.playSilence(1000, TextToSpeech.QUEUE_ADD, null);\n tts.speak(getResources().getString(R.string.catDesc), TextToSpeech.QUEUE_ADD, null);\n tts.playSilence(1000, TextToSpeech.QUEUE_ADD, null);\n }\n\n}\n @Override\nprotected void onDestroy() {\n if (tts != null)\n …Run Code Online (Sandbox Code Playgroud)