优化
This commit is contained in:
@@ -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()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user