Skip to content

Commit

Permalink
fix: websocket failure may stop tts functioning
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Sep 25, 2024
1 parent 4e25b16 commit 4404717
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/src/main/java/info/plateaukao/einkbro/tts/ETts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4404717

Please sign in to comment.