Horis 1 år sedan
förälder
incheckning
66730e0ed4
1 ändrade filer med 9 tillägg och 4 borttagningar
  1. 9 4
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt

+ 9 - 4
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()
+                            )
                         }
                     }
                 }