From 0750576ff9dd26b1f3234db6537b7ad99a4b6d56 Mon Sep 17 00:00:00 2001 From: Johnson Sun Date: Thu, 7 Nov 2024 11:03:48 -0500 Subject: [PATCH] fix: Byte mismatch issue I hypothesize that this is due to a potential race condition between two recorders when the keyboard has been destroyed while recording. When the keyboard has been recreated, it will start a second new recorder. Since the first recorder isn't stopped, sending a request based on the file may lead to mismatch between file header size and actual file size, since the file is being written to while being read. Full error message: ``` expected X bytes but received Y ``` Note that Y will be larger than X. Fixes: https://github.com/j3soon/whisper-to-input/issues/40 --- .../java/com/example/whispertoinput/WhisperInputService.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/android/app/src/main/java/com/example/whispertoinput/WhisperInputService.kt b/android/app/src/main/java/com/example/whispertoinput/WhisperInputService.kt index 2b58715..ba78683 100644 --- a/android/app/src/main/java/com/example/whispertoinput/WhisperInputService.kt +++ b/android/app/src/main/java/com/example/whispertoinput/WhisperInputService.kt @@ -211,4 +211,10 @@ class WhisperInputService : InputMethodService() { recorderManager!!.stop() } + override fun onDestroy() { + super.onDestroy() + whisperTranscriber.stop() + whisperKeyboard.reset() + recorderManager!!.stop() + } }