tts朗读跳过全标点段落

pull/2628/head
kunfei 2 years ago
parent 212484e8f0
commit 0aec880e5b
  1. 24
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt

@ -86,10 +86,12 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
return return
} }
for (i in nowSpeak until contentList.size) { for (i in nowSpeak until contentList.size) {
val text = contentList[i].replace(AppPattern.notReadAloudRegex, "") val text = contentList[i]
result = tts.speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i) if (!text.matches(AppPattern.notReadAloudRegex)) {
if (result == TextToSpeech.ERROR) { result = tts.speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i)
AppLog.put("tts朗读出错:$text") if (result == TextToSpeech.ERROR) {
AppLog.put("tts朗读出错:$text")
}
} }
} }
}.onFailure { }.onFailure {
@ -150,11 +152,15 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
} }
override fun onDone(s: String) { override fun onDone(s: String) {
readAloudNumber += contentList[nowSpeak].length + 1 //跳过全标点段落
nowSpeak++ do {
if (nowSpeak >= contentList.size) { readAloudNumber += contentList[nowSpeak].length + 1
nextChapter() nowSpeak++
} if (nowSpeak >= contentList.size) {
nextChapter()
return
}
} while (contentList[nowSpeak].matches(AppPattern.notReadAloudRegex))
} }
override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) { override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) {

Loading…
Cancel
Save