diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 4e90b7d82..e680d1e8c 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -4,4 +4,6 @@ object Bus { const val RECREATE = "RECREATE" const val UP_BOOK = "sourceDebugLog" const val ALOUD_STATE = "aloud_state" + const val TTS_START = "ttsStart" + const val TTS_RANGE_START = "readAloudNumber" } \ No newline at end of file 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 392901820..ebb4513da 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -268,11 +268,21 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage private inner class TTSUtteranceListener : UtteranceProgressListener() { override fun onStart(s: String) { - + postEvent(Bus.TTS_START, readAloudNumber + 1) + postEvent(Bus.TTS_RANGE_START, readAloudNumber + 1) } override fun onDone(s: String) { + readAloudNumber += contentList[nowSpeak].length + 1 + nowSpeak += 1 + if (nowSpeak >= contentList.size) { + postEvent(Bus.ALOUD_STATE, Status.NEXT) + } + } + override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) { + super.onRangeStart(utteranceId, start, end, frame) + postEvent(Bus.TTS_RANGE_START, readAloudNumber + start) } override fun onError(s: String) {