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

@ -68,9 +68,10 @@ class HttpReadAloudService : BaseReadAloudService(),
ReadBook.readAloud()
} else {
super.play()
ReadAloud.httpTTS?.let {
kotlin.runCatching {
val tts = ReadAloud.httpTTS ?: throw NoStackTraceException("httpTts is null")
val fileName =
md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), contentList[nowSpeak])
md5SpeakFileName(tts.url, AppConfig.ttsSpeechRate.toString(), contentList[nowSpeak])
if (nowSpeak == 0) {
downloadAudio()
} else {
@ -81,6 +82,8 @@ class HttpReadAloudService : BaseReadAloudService(),
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.MediaHelp
import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.ReadBook
import io.legado.app.utils.*
import java.util.*
@ -75,12 +76,11 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
super.play()
kotlin.runCatching {
MediaHelp.playSilentSound(this@TTSReadAloudService)
textToSpeech!!.let {
it.speak("", TextToSpeech.QUEUE_FLUSH, null, null)
val tts = textToSpeech ?: throw NoStackTraceException("tts is null")
tts.speak("", TextToSpeech.QUEUE_FLUSH, null, null)
for (i in nowSpeak until contentList.size) {
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 {
AppLog.put("tts朗读出错", it)

Loading…
Cancel
Save