From 1b8fd1036825db0b652c8cc13fe0c21c78838cb5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 8 Sep 2019 17:18:24 +0800 Subject: [PATCH] up --- .../io/legado/app/service/ReadAloudService.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/ReadAloudService.kt b/app/src/main/java/io/legado/app/service/ReadAloudService.kt index 114b0bf72..42f214931 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -120,6 +120,9 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, } private val handler = Handler() + private val ttsParams by lazy { + hashMapOf(Pair(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "content")) + } private var ttsIsSuccess: Boolean = false private lateinit var audioManager: AudioManager private lateinit var mFocusRequest: AudioFocusRequest @@ -234,14 +237,22 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, ReadAloudNotification.upNotification(this) for (i in nowSpeak until contentList.size) { if (i == 0) { - textToSpeech?.speak(contentList[i], TextToSpeech.QUEUE_FLUSH, null, "content$i") + speak(contentList[i], TextToSpeech.QUEUE_FLUSH) } else { - textToSpeech?.speak(contentList[i], TextToSpeech.QUEUE_ADD, null, "content$i") + speak(contentList[i], TextToSpeech.QUEUE_ADD) } } } } + private fun speak(content: String, queueMode: Int) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + textToSpeech?.speak(content, queueMode, null, "content") + } else { + textToSpeech?.speak(content, queueMode, ttsParams) + } + } + private fun setTimer(minute: Int) { timeMinute = minute if (minute > 0) {