From b446d59c4021bcddb2a43fd7dc5cd213e2be7530 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Jul 2021 08:15:15 +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/service/TTSReadAloudService.kt | 5 +---- .../io/legado/app/ui/book/read/TextActionMenu.kt | 13 +++++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index d814d4e09..16ad9c52a 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -13,7 +13,6 @@ import io.legado.app.service.help.ReadBook import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.postEvent import io.legado.app.utils.toastOnUi -import kotlinx.coroutines.launch import java.util.* class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener { @@ -56,9 +55,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener play() } } else { - launch { - toastOnUi(R.string.tts_init_failed) - } + toastOnUi(R.string.tts_init_failed) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index 75f8e30b0..b4296247b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -167,17 +167,22 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac } if (!ttsInitFinish) return if (text == "") return - if (textToSpeech?.isSpeaking == true) + if (textToSpeech?.isSpeaking == true) { textToSpeech?.stop() + } textToSpeech?.speak(text, TextToSpeech.QUEUE_ADD, null, "select_text") lastText = "" } @Synchronized override fun onInit(status: Int) { - textToSpeech?.language = Locale.CHINA - ttsInitFinish = true - readAloud(lastText) + if (status == TextToSpeech.SUCCESS) { + textToSpeech?.language = Locale.CHINA + ttsInitFinish = true + readAloud(lastText) + } else { + context.toastOnUi(R.string.tts_init_failed) + } } @RequiresApi(Build.VERSION_CODES.M)