pull/1592/head
kunfei 3 years ago
parent 313ca3c2d3
commit f614182b07
  1. 8
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  2. 8
      app/src/main/java/io/legado/app/utils/ToastUtils.kt

@ -73,16 +73,18 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
ReadBook.readAloud() ReadBook.readAloud()
} else { } else {
super.play() super.play()
execute { kotlin.runCatching {
MediaHelp.playSilentSound(this@TTSReadAloudService) MediaHelp.playSilentSound(this@TTSReadAloudService)
}.onFinally { textToSpeech!!.let {
textToSpeech?.let {
it.speak("", TextToSpeech.QUEUE_FLUSH, null, null) it.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) it.speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i)
} }
} }
}.onFailure {
AppLog.put("tts朗读出错", it)
toastOnUi(it.localizedMessage)
} }
} }
} }

@ -26,9 +26,9 @@ fun Context.toastOnUi(message: CharSequence?) {
runOnUI { runOnUI {
kotlin.runCatching { kotlin.runCatching {
if (toast == null) { if (toast == null) {
toast = Toast.makeText(this, message, Toast.LENGTH_SHORT) toast = Toast.makeText(this, message.toString(), Toast.LENGTH_SHORT)
} else { } else {
toast?.setText(message) toast?.setText(message.toString())
toast?.duration = Toast.LENGTH_SHORT toast?.duration = Toast.LENGTH_SHORT
} }
toast?.show() toast?.show()
@ -54,9 +54,9 @@ fun Context.longToastOnUi(message: CharSequence?) {
runOnUI { runOnUI {
kotlin.runCatching { kotlin.runCatching {
if (toast == null) { if (toast == null) {
toast = Toast.makeText(this, message, Toast.LENGTH_LONG) toast = Toast.makeText(this, message.toString(), Toast.LENGTH_LONG)
} else { } else {
toast?.setText(message) toast?.setText(message.toString())
toast?.duration = Toast.LENGTH_LONG toast?.duration = Toast.LENGTH_LONG
} }
toast?.show() toast?.show()

Loading…
Cancel
Save