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 35d5f564..298bf08a 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 @@ -114,7 +114,7 @@ class SpeechRecognizerDictationService: DictationService, KoinComponent { }) speechRecognizer.startListening(intent) awaitClose { - + speechRecognizer.destroy() } }.flowOn(Dispatchers.Main) @@ -222,6 +222,7 @@ class SpeechRecognizerDictationService: DictationService, KoinComponent { Logging.d("Speech recognition results: ${status.results}") if (status.results.firstOrNull()?.second?.isBlank() != false) { emit(DictationServiceResponse.Transcription(emptyList())) + emit(DictationServiceResponse.Complete) return@collect } emit(DictationServiceResponse.Transcription( @@ -240,7 +241,6 @@ class SpeechRecognizerDictationService: DictationService, KoinComponent { } finally { //audioTrack.stop() audioJob.cancel() - speechRecognizer.destroy() decoder.close() } diff --git a/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/VoiceSessionHandler.kt b/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/VoiceSessionHandler.kt index 4696b750..42965c9d 100644 --- a/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/VoiceSessionHandler.kt +++ b/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/VoiceSessionHandler.kt @@ -54,65 +54,63 @@ class VoiceSessionHandler( .takeWhile { it !is DictationServiceResponse.Complete } .onEach { Logging.v("DictationServiceResponse: $it") - withTimeout(1.minutes) { - when (it) { - is DictationServiceResponse.Ready -> { - pebbleDevice.activeVoiceSession.value = voiceSession - val result = SessionSetupResult( - sessionType = SessionType.Dictation, - result = Result.Success - ) - if (appInitiated) { - result.flags.set(1u) - } - pebbleDevice.voiceService.send(result) - sentReady = true - } - is DictationServiceResponse.Error -> { - val result = if (sentReady) { - DictationResult( - voiceSession.sessionId.toUShort(), - it.result, - buildList { - if (appInitiated && voiceSession.appUuid != null) { - add(VoiceAttribute.AppUuid().apply { - uuid.set(voiceSession.appUuid) - }) - } - } - ) - } else { - SessionSetupResult( - sessionType = SessionType.Dictation, - result = it.result - ) - } - if (appInitiated) { - result.flags.set(1u) - } - pebbleDevice.voiceService.send(result) + when (it) { + is DictationServiceResponse.Ready -> { + pebbleDevice.activeVoiceSession.value = voiceSession + val result = SessionSetupResult( + sessionType = SessionType.Dictation, + result = Result.Success + ) + if (appInitiated) { + result.flags.set(1u) } - is DictationServiceResponse.Transcription -> { - val resp = DictationResult( + pebbleDevice.voiceService.send(result) + sentReady = true + } + is DictationServiceResponse.Error -> { + val result = if (sentReady) { + DictationResult( voiceSession.sessionId.toUShort(), - Result.Success, + it.result, buildList { - add(makeTranscription(it.sentences)) if (appInitiated && voiceSession.appUuid != null) { - add(VoiceAttribute( - id = VoiceAttributeType.AppUuid.value, - content = VoiceAttribute.AppUuid().apply { - uuid.set(voiceSession.appUuid) - } - )) + add(VoiceAttribute.AppUuid().apply { + uuid.set(voiceSession.appUuid) + }) } } ) - if (appInitiated) { - resp.flags.set(1u) - } - pebbleDevice.voiceService.send(resp) + } else { + SessionSetupResult( + sessionType = SessionType.Dictation, + result = it.result + ) + } + if (appInitiated) { + result.flags.set(1u) } + pebbleDevice.voiceService.send(result) + } + is DictationServiceResponse.Transcription -> { + val resp = DictationResult( + voiceSession.sessionId.toUShort(), + Result.Success, + buildList { + add(makeTranscription(it.sentences)) + if (appInitiated && voiceSession.appUuid != null) { + add(VoiceAttribute( + id = VoiceAttributeType.AppUuid.value, + content = VoiceAttribute.AppUuid().apply { + uuid.set(voiceSession.appUuid) + } + )) + } + } + ) + if (appInitiated) { + resp.flags.set(1u) + } + pebbleDevice.voiceService.send(resp) } } } @@ -170,9 +168,7 @@ class VoiceSessionHandler( val dictationService: DictationService by inject() val voiceSession = VoiceSession(appUuid, message.sessionId.get().toInt(), encoderInfo, dictationService) Logging.d("Received voice session: $voiceSession") - coroutineScope { - launch { handleSpeechStream(voiceSession) } - } + handleSpeechStream(voiceSession) } }