Skip to content

Commit

Permalink
log error name in speechrecognizer
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Nov 5, 2024
1 parent ed85294 commit 498ca14
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ class SpeechRecognizerDictationService: DictationService, KoinComponent {
when (status) {
is SpeechRecognizerStatus.Ready -> emit(DictationServiceResponse.Ready)
is SpeechRecognizerStatus.Error -> {
Logging.e("Speech recognition error: ${status.error}")
when (status.error) {
SpeechRecognizer.ERROR_NETWORK -> emit(DictationServiceResponse.Error(Result.FailServiceUnavailable))
SpeechRecognizer.ERROR_SPEECH_TIMEOUT -> emit(DictationServiceResponse.Error(Result.FailTimeout))
SpeechRecognizer.ERROR_NO_MATCH -> emit(DictationServiceResponse.Transcription(emptyList()))
val error = SpeechRecognizerError.fromInt(status.error)
Logging.e("Speech recognition error: ${error.name}")
when (error) {
SpeechRecognizerError.ERROR_NETWORK -> emit(DictationServiceResponse.Error(Result.FailServiceUnavailable))
SpeechRecognizerError.ERROR_SPEECH_TIMEOUT -> emit(DictationServiceResponse.Error(Result.FailTimeout))
SpeechRecognizerError.ERROR_NO_MATCH -> emit(DictationServiceResponse.Transcription(emptyList()))
else -> emit(DictationServiceResponse.Error(Result.FailServiceUnavailable))
}
emit(DictationServiceResponse.Complete)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.rebble.cobble.shared.domain.voice.speechrecognizer
enum class SpeechRecognizerError {
ERROR_NETWORK_TIMEOUT,
ERROR_NETWORK,
ERROR_AUDIO,
ERROR_SERVER,
ERROR_CLIENT,
ERROR_SPEECH_TIMEOUT,
ERROR_NO_MATCH,
ERROR_RECOGNIZER_BUSY,
ERROR_INSUFFICIENT_PERMISSIONS,
ERROR_TOO_MANY_REQUESTS,
ERROR_SERVER_DISCONNECTED,
ERROR_LANGUAGE_NOT_SUPPORTED,
ERROR_LANGUAGE_UNAVAILABLE,
ERROR_CANNOT_CHECK_SUPPORT,
ERROR_CANNOT_LISTEN_TO_DOWNLOAD_EVENTS;

companion object {
fun fromInt(value: Int): SpeechRecognizerError {
return when (value) {
1 -> ERROR_NETWORK_TIMEOUT
2 -> ERROR_NETWORK
3 -> ERROR_AUDIO
4 -> ERROR_SERVER
5 -> ERROR_CLIENT
6 -> ERROR_SPEECH_TIMEOUT
7 -> ERROR_NO_MATCH
8 -> ERROR_RECOGNIZER_BUSY
9 -> ERROR_INSUFFICIENT_PERMISSIONS
10 -> ERROR_TOO_MANY_REQUESTS
11 -> ERROR_SERVER_DISCONNECTED
12 -> ERROR_LANGUAGE_NOT_SUPPORTED
13 -> ERROR_LANGUAGE_UNAVAILABLE
14 -> ERROR_CANNOT_CHECK_SUPPORT
15 -> ERROR_CANNOT_LISTEN_TO_DOWNLOAD_EVENTS
else -> throw IllegalArgumentException("Unknown error code: $value")
}
}
}
}

0 comments on commit 498ca14

Please sign in to comment.