diff --git a/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/SpeechRecognizerDictationService.kt b/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/SpeechRecognizerDictationService.kt index de28027a..a7f845e6 100644 --- a/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/SpeechRecognizerDictationService.kt +++ b/android/shared/src/androidMain/kotlin/io/rebble/cobble/shared/domain/voice/SpeechRecognizerDictationService.kt @@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.* import org.koin.core.component.KoinComponent import org.koin.core.component.inject import java.nio.ByteBuffer +import java.nio.ShortBuffer @RequiresApi(VERSION_CODES.TIRAMISU) @@ -28,7 +29,7 @@ class SpeechRecognizerDictationService: DictationService, KoinComponent { private val scope = CoroutineScope(Dispatchers.IO) sealed class SpeechRecognizerStatus { - object Ready: SpeechRecognizerStatus() + data object Ready: SpeechRecognizerStatus() class Error(val error: Int): SpeechRecognizerStatus() class Results(val results: List>): SpeechRecognizerStatus() } @@ -143,11 +144,11 @@ class SpeechRecognizerDictationService: DictationService, KoinComponent { speechRecognizer.stopListening() } } else if (frame is AudioStreamFrame.AudioData) { - decodedBuf.rewind() val result = decoder.decodeFrame(frame.data, decodedBuf, hasHeaderByte = true) if (result != SpeexDecodeResult.Success) { Logging.e("Speex decode error: ${result.name}") } + decodedBuf.rewind() recognizerWritePipe.write(decodedBuf.array(), decodedBuf.arrayOffset(), decodeBufLength) } } @@ -173,6 +174,10 @@ class SpeechRecognizerDictationService: DictationService, KoinComponent { } is SpeechRecognizerStatus.Results -> { Logging.d("Speech recognition results: ${status.results}") + if (status.results.firstOrNull()?.second?.isBlank() != false) { + emit(DictationServiceResponse.Transcription(emptyList())) + return@collect + } emit(DictationServiceResponse.Transcription( listOf( buildList { 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 7dea26cc..2bf1a7a2 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 @@ -92,18 +92,28 @@ class VoiceSessionHandler( sentReady = true } is DictationServiceResponse.Error -> { - if (sentReady) { - pebbleDevice.voiceService.send(DictationResult( + val result = if (sentReady) { + DictationResult( voiceSession.sessionId.toUShort(), it.result, - emptyList() - )) + buildList { + if (appInitiated && voiceSession.appUuid != null) { + add(VoiceAttribute.AppUuid().apply { + uuid.set(voiceSession.appUuid) + }) + } + } + ) } else { - pebbleDevice.voiceService.send(SessionSetupResult( + SessionSetupResult( sessionType = SessionType.Dictation, result = it.result - )) + ) } + if (appInitiated) { + result.flags.set(1u) + } + pebbleDevice.voiceService.send(result) } is DictationServiceResponse.Transcription -> { val resp = DictationResult(