diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 09f122f18..0bd8b96cc 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -73,16 +73,18 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener ReadBook.readAloud() } else { super.play() - execute { + kotlin.runCatching { MediaHelp.playSilentSound(this@TTSReadAloudService) - }.onFinally { - textToSpeech?.let { + textToSpeech!!.let { it.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) } } + }.onFailure { + AppLog.put("tts朗读出错", it) + toastOnUi(it.localizedMessage) } } } diff --git a/app/src/main/java/io/legado/app/utils/ToastUtils.kt b/app/src/main/java/io/legado/app/utils/ToastUtils.kt index a2373f819..c2a91858f 100644 --- a/app/src/main/java/io/legado/app/utils/ToastUtils.kt +++ b/app/src/main/java/io/legado/app/utils/ToastUtils.kt @@ -26,9 +26,9 @@ fun Context.toastOnUi(message: CharSequence?) { runOnUI { kotlin.runCatching { if (toast == null) { - toast = Toast.makeText(this, message, Toast.LENGTH_SHORT) + toast = Toast.makeText(this, message.toString(), Toast.LENGTH_SHORT) } else { - toast?.setText(message) + toast?.setText(message.toString()) toast?.duration = Toast.LENGTH_SHORT } toast?.show() @@ -54,9 +54,9 @@ fun Context.longToastOnUi(message: CharSequence?) { runOnUI { kotlin.runCatching { if (toast == null) { - toast = Toast.makeText(this, message, Toast.LENGTH_LONG) + toast = Toast.makeText(this, message.toString(), Toast.LENGTH_LONG) } else { - toast?.setText(message) + toast?.setText(message.toString()) toast?.duration = Toast.LENGTH_LONG } toast?.show()