From 078a42d0d87883f79b1cdced200184f6cd266e19 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 27 Sep 2022 14:41:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 645b2d04a..7978b7ce7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -141,7 +141,7 @@ class ReadBookActivity : BaseReadBookActivity(), private var autoPageJob: Job? = null private var backupJob: Job? = null private var keepScreenJon: Job? = null - private val tts by lazy { TTS() } + private var tts: TTS? = null val textActionMenu: TextActionMenu by lazy { TextActionMenu(this, this) } @@ -633,7 +633,7 @@ class ReadBookActivity : BaseReadBookActivity(), when (itemId) { R.id.menu_aloud -> when (AppConfig.contentSelectSpeakMod) { 1 -> binding.readView.aloudStartSelect() - else -> tts.speak(binding.readView.getSelectText()) + else -> speak(binding.readView.getSelectText()) } R.id.menu_bookmark -> binding.readView.curPage.let { val bookmark = it.createBookmark() @@ -683,6 +683,13 @@ class ReadBookActivity : BaseReadBookActivity(), readView.isTextSelected = false } + private fun speak(text: String) { + if (tts == null) { + tts = TTS() + } + tts?.speak(text) + } + /** * 鼠标滚轮翻页 */ @@ -1196,7 +1203,7 @@ class ReadBookActivity : BaseReadBookActivity(), override fun onDestroy() { super.onDestroy() - tts.clearTts() + tts?.clearTts() textActionMenu.dismiss() popupAction.dismiss() binding.readView.onDestroy()