From a3ddf6a435b846113641d9e57a02f88da3fe6fcc Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Apr 2020 20:45:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 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 1f63dac89..8d8c5f39f 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -20,11 +20,13 @@ import java.util.* class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener { companion object { - var textToSpeech: TextToSpeech? = null + private var textToSpeech: TextToSpeech? = null fun clearTTS() { - textToSpeech?.stop() - textToSpeech?.shutdown() + textToSpeech?.let { + it.stop() + it.shutdown() + } textToSpeech = null } } @@ -45,9 +47,11 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener @Synchronized override fun onInit(status: Int) { if (status == TextToSpeech.SUCCESS) { - textToSpeech?.language = Locale.CHINA - textToSpeech?.setOnUtteranceProgressListener(TTSUtteranceListener()) - ttsInitFinish = true + textToSpeech?.let { + it.language = Locale.CHINA + it.setOnUtteranceProgressListener(TTSUtteranceListener()) + ttsInitFinish = true + } play() } else { launch {