Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

fix: preserve dictation when post-processing returns blank text (#2290)

daydreamer.jin889fca0d1cf3
diff --git a/src-tauri/src/actions.rs b/src-tauri/src/actions.rs
index c4d6e174..5ccd6b2c 100644
--- a/src-tauri/src/actions.rs
+++ b/src-tauri/src/actions.rs
@@ -151,6 +151,17 @@ fn is_blank_transcription(transcription: &str) -> bool {
transcription.trim().is_empty()
}
+fn non_blank_post_processed_text(text: String) -> Option<String> {
+ if is_blank_transcription(&text) {
+ warn!(
+ "Post-processing returned an empty response. Falling back to original transcription."
+ );
+ None
+ } else {
+ Some(text)
+ }
+}
+
async fn complete_unless_cancelled<F, C>(operation: F, is_cancelled: C) -> Option<F::Output>
where
F: Future,
@@ -418,7 +429,10 @@ pub(crate) async fn process_transcription_output(
let mut post_process_prompt: Option<String> = None;
if post_process {
- if let Some(processed_text) = post_process_transcription(&settings, &final_text).await {
+ if let Some(processed_text) = post_process_transcription(&settings, &final_text)
+ .await
+ .and_then(non_blank_post_processed_text)
+ {
post_processed_text = Some(processed_text.clone());
final_text = processed_text;
@@ -988,8 +1002,8 @@ pub static ACTION_MAP: Lazy<HashMap<String, Arc<dyn ShortcutAction>>> = Lazy::ne
#[cfg(test)]
mod tests {
use super::{
- complete_unless_cancelled, is_blank_transcription, should_use_streaming_overlay,
- strip_think_block,
+ complete_unless_cancelled, is_blank_transcription, non_blank_post_processed_text,
+ should_use_streaming_overlay, strip_invisible_chars, strip_think_block,
};
use crate::settings::OverlayStyle;
use std::future;
@@ -1011,6 +1025,35 @@ mod tests {
assert!(!is_blank_transcription(" hello "));
}
+ #[test]
+ fn blank_post_processed_text_is_rejected() {
+ for text in ["", " ", "\t\n\r\n", "\u{00A0}\u{2003}"] {
+ assert_eq!(non_blank_post_processed_text(text.to_string()), None);
+ }
+ }
+
+ #[test]
+ fn cleaned_empty_post_processed_text_is_rejected() {
+ for text in [
+ "\u{200B}\u{200C}\u{200D}\u{FEFF}",
+ "<think>reasoning only</think>",
+ "<think>reasoning only</think>\n\u{200B} ",
+ ] {
+ let text = strip_invisible_chars(strip_think_block(text));
+ assert_eq!(non_blank_post_processed_text(text), None);
+ }
+ }
+
+ #[test]
+ fn non_blank_post_processed_text_is_preserved() {
+ for text in ["Cleaned text.", " 정리된 문장입니다.\n", "0"] {
+ assert_eq!(
+ non_blank_post_processed_text(text.to_string()),
+ Some(text.to_string())
+ );
+ }
+ }
+
#[test]
fn completed_operation_returns_its_output() {
let result = tauri::async_runtime::block_on(complete_unless_cancelled(