pull/1592/head
kunfei 3 years ago
parent d410c17acf
commit ad16469210
  1. 7
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  2. 12
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt

@ -68,9 +68,10 @@ class HttpReadAloudService : BaseReadAloudService(),
ReadBook.readAloud() ReadBook.readAloud()
} else { } else {
super.play() super.play()
ReadAloud.httpTTS?.let { kotlin.runCatching {
val tts = ReadAloud.httpTTS ?: throw NoStackTraceException("httpTts is null")
val fileName = val fileName =
md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), contentList[nowSpeak]) md5SpeakFileName(tts.url, AppConfig.ttsSpeechRate.toString(), contentList[nowSpeak])
if (nowSpeak == 0) { if (nowSpeak == 0) {
downloadAudio() downloadAudio()
} else { } else {
@ -81,6 +82,8 @@ class HttpReadAloudService : BaseReadAloudService(),
downloadAudio() downloadAudio()
} }
} }
}.onFailure {
toastOnUi("朗读出错:${it.localizedMessage}")
} }
} }
} }

@ -11,6 +11,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.MediaHelp import io.legado.app.help.MediaHelp
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.utils.* import io.legado.app.utils.*
import java.util.* import java.util.*
@ -75,12 +76,11 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
super.play() super.play()
kotlin.runCatching { kotlin.runCatching {
MediaHelp.playSilentSound(this@TTSReadAloudService) MediaHelp.playSilentSound(this@TTSReadAloudService)
textToSpeech!!.let { val tts = textToSpeech ?: throw NoStackTraceException("tts is null")
it.speak("", TextToSpeech.QUEUE_FLUSH, null, null) tts.speak("", TextToSpeech.QUEUE_FLUSH, null, null)
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].replace(AppPattern.notReadAloudRegex, "")
it.speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i) tts.speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i)
}
} }
}.onFailure { }.onFailure {
AppLog.put("tts朗读出错", it) AppLog.put("tts朗读出错", it)

Loading…
Cancel
Save