From 66730e0ed4d017820ea5111a2d836e0462adcbbe Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Tue, 1 Apr 2025 17:51:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/HttpReadAloudService.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 79a9aee7e..c7ceaae08 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -284,12 +284,14 @@ class HttpReadAloudService : BaseReadAloudService(), null } else { kotlin.runCatching { - runBlocking { + runBlocking(lifecycleScope.coroutineContext[Job]!!) { getSpeakStream(httpTts, speakText) } }.onFailure { when (it) { - is InterruptedException -> Unit + is InterruptedException, + is CancellationException -> Unit + else -> pauseReadAloud() } }.getOrThrow() @@ -338,12 +340,15 @@ class HttpReadAloudService : BaseReadAloudService(), response = analyzeUrl.evalJS(checkJs, response) as Response } response.headers["Content-Type"]?.let { contentType -> + val contentType = contentType.substringBefore(";") val ct = httpTts.contentType - if (contentType == "application/json") { + if (contentType == "application/json" || contentType.startsWith("text/")) { throw NoStackTraceException(response.body!!.string()) } else if (ct?.isNotBlank() == true) { if (!contentType.matches(ct.toRegex())) { - throw NoStackTraceException("TTS服务器返回错误:" + response.body!!.string()) + throw NoStackTraceException( + "TTS服务器返回错误:" + response.body!!.string() + ) } } }