fix: EdgeTTS 用独立 OkHttpClient,去掉业务拦截器干扰
WebSocket 连接经过了 SignatureInterceptor/UnbindInterceptor 导致连接被重置。 改为独立的 OkHttpClient,不带任何业务拦截器。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,10 +22,18 @@ import javax.inject.Singleton
|
||||
*/
|
||||
@Singleton
|
||||
class EdgeTtsManager @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val okHttpClient: OkHttpClient
|
||||
@ApplicationContext private val context: Context
|
||||
) {
|
||||
|
||||
/**
|
||||
* TTS 专用 OkHttpClient(不带业务拦截器)
|
||||
* 业务拦截器(SignatureInterceptor、UnbindInterceptor)会干扰 WebSocket 连接
|
||||
*/
|
||||
private val ttsClient = OkHttpClient.Builder()
|
||||
.connectTimeout(10, java.util.concurrent.TimeUnit.SECONDS)
|
||||
.readTimeout(30, java.util.concurrent.TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
companion object {
|
||||
private const val TAG = "EdgeTTS"
|
||||
|
||||
@@ -146,7 +154,7 @@ class EdgeTtsManager @Inject constructor(
|
||||
val audioBuffer = ByteArrayOutputStream()
|
||||
var resumed = false
|
||||
|
||||
val ws = okHttpClient.newWebSocket(request, object : WebSocketListener() {
|
||||
val ws = ttsClient.newWebSocket(request, object : WebSocketListener() {
|
||||
override fun onOpen(webSocket: WebSocket, response: Response) {
|
||||
Timber.d("$TAG: WebSocket 已连接")
|
||||
|
||||
@@ -182,7 +190,7 @@ class EdgeTtsManager @Inject constructor(
|
||||
}
|
||||
|
||||
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
||||
Timber.e(t, "$TAG: WebSocket 连接失败")
|
||||
Timber.e(t, "$TAG: WebSocket 连接失败, response=${response?.code}, url=$url")
|
||||
// 尝试从错误响应中修正时钟偏移
|
||||
response?.header("Date")?.let { adjustClockSkew(it) }
|
||||
if (!resumed) {
|
||||
|
||||
Reference in New Issue
Block a user