This commit is contained in:
Horis
2025-04-01 17:51:26 +08:00
parent 14e2d1946e
commit 66730e0ed4
@@ -284,12 +284,14 @@ class HttpReadAloudService : BaseReadAloudService(),
null null
} else { } else {
kotlin.runCatching { kotlin.runCatching {
runBlocking { runBlocking(lifecycleScope.coroutineContext[Job]!!) {
getSpeakStream(httpTts, speakText) getSpeakStream(httpTts, speakText)
} }
}.onFailure { }.onFailure {
when (it) { when (it) {
is InterruptedException -> Unit is InterruptedException,
is CancellationException -> Unit
else -> pauseReadAloud() else -> pauseReadAloud()
} }
}.getOrThrow() }.getOrThrow()
@@ -338,12 +340,15 @@ class HttpReadAloudService : BaseReadAloudService(),
response = analyzeUrl.evalJS(checkJs, response) as Response response = analyzeUrl.evalJS(checkJs, response) as Response
} }
response.headers["Content-Type"]?.let { contentType -> response.headers["Content-Type"]?.let { contentType ->
val contentType = contentType.substringBefore(";")
val ct = httpTts.contentType val ct = httpTts.contentType
if (contentType == "application/json") { if (contentType == "application/json" || contentType.startsWith("text/")) {
throw NoStackTraceException(response.body!!.string()) throw NoStackTraceException(response.body!!.string())
} else if (ct?.isNotBlank() == true) { } else if (ct?.isNotBlank() == true) {
if (!contentType.matches(ct.toRegex())) { if (!contentType.matches(ct.toRegex())) {
throw NoStackTraceException("TTS服务器返回错误:" + response.body!!.string()) throw NoStackTraceException(
"TTS服务器返回错误:" + response.body!!.string()
)
} }
} }
} }