diff --git a/app/src/main/java/info/plateaukao/einkbro/tts/ETts.kt b/app/src/main/java/info/plateaukao/einkbro/tts/ETts.kt index e7f873ce..678a6ca8 100644 --- a/app/src/main/java/info/plateaukao/einkbro/tts/ETts.kt +++ b/app/src/main/java/info/plateaukao/einkbro/tts/ETts.kt @@ -35,9 +35,9 @@ class ETts { private val okHttpClient by lazy { OkHttpClient.Builder() - .readTimeout(30, TimeUnit.SECONDS) - .writeTimeout(30, TimeUnit.SECONDS) - .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(15, TimeUnit.SECONDS) + .writeTimeout(15, TimeUnit.SECONDS) + .connectTimeout(15, TimeUnit.SECONDS) .build() } @@ -82,6 +82,12 @@ class ETts { override fun onClosed(webSocket: WebSocket, code: Int, reason: String) { continuation.resume(byteArray) } + override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { + super.onFailure(webSocket, t, response) + response?.close() + Log.d("TTSWebSocketListener", "onFailure: ${t.message}") + continuation.resume(null) + } }) client.send(audioFormat) client.send(ssmlHeadersPlusData) diff --git a/app/src/main/java/info/plateaukao/einkbro/viewmodel/TtsViewModel.kt b/app/src/main/java/info/plateaukao/einkbro/viewmodel/TtsViewModel.kt index 8a61c2b8..25ac89e9 100644 --- a/app/src/main/java/info/plateaukao/einkbro/viewmodel/TtsViewModel.kt +++ b/app/src/main/java/info/plateaukao/einkbro/viewmodel/TtsViewModel.kt @@ -211,8 +211,14 @@ class TtsViewModel : ViewModel(), KoinComponent { mediaPlayer.reset() cont.resume(0) } + mediaPlayer.setOnErrorListener { value1, value2, value3 -> + Log.e("TtsViewModel", "playAudioArray: error $value1 $value2 $value3") + mediaPlayer.reset() + cont.resume(0) + true + } } catch (e: Exception) { - Log.e("TtsViewModel", "playAudioArray: ${e.message}") + Log.e("TtsViewModel", "playAudioArray exception: ${e.message}") mediaPlayer.reset() cont.resume(0) }