diff --git a/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/speechrecognizer/SpeechRecognizerDictationService.kt b/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/speechrecognizer/SpeechRecognizerDictationService.kt index 0c3f31ce..b99b7ebc 100644 --- a/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/speechrecognizer/SpeechRecognizerDictationService.kt +++ b/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/speechrecognizer/SpeechRecognizerDictationService.kt @@ -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) diff --git a/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/speechrecognizer/SpeechRecognizerError.kt b/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/speechrecognizer/SpeechRecognizerError.kt new file mode 100644 index 00000000..7c4e90eb --- /dev/null +++ b/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/speechrecognizer/SpeechRecognizerError.kt @@ -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") + } + } + } +} \ No newline at end of file