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) {