From 075fb5f78dad3247e4ea8885016bb06550eff5ec Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Sat, 28 Mar 2026 11:40:47 +0100 Subject: [PATCH] [bugfix] remove long repeating words (#976) * audio_toolkit: remove long repeating words I've noticed a couple of times that Paraket v3 may produce repeats of words that are not folded by Handy so I propose to lift up word length limitation. * Update text.rs --------- Co-authored-by: CJ Pais --- src-tauri/src/audio_toolkit/text.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/audio_toolkit/text.rs b/src-tauri/src/audio_toolkit/text.rs index 29f43ff..2cd3171 100644 --- a/src-tauri/src/audio_toolkit/text.rs +++ b/src-tauri/src/audio_toolkit/text.rs @@ -231,7 +231,7 @@ fn get_filler_words_for_language(lang: &str) -> &'static [&'static str] { static MULTI_SPACE_PATTERN: Lazy = Lazy::new(|| Regex::new(r"\s{2,}").unwrap()); -/// Collapses repeated 1-2 letter words (3+ repetitions) to a single instance. +/// Collapses repeated words (3+ repetitions) to a single instance. /// E.g., "wh wh wh wh" -> "wh", "I I I I" -> "I" fn collapse_stutters(text: &str) -> String { let words: Vec<&str> = text.split_whitespace().collect(); @@ -246,8 +246,7 @@ fn collapse_stutters(text: &str) -> String { let word = words[i]; let word_lower = word.to_lowercase(); - // Only process 1-2 letter words - if word_lower.len() <= 2 && word_lower.chars().all(|c| c.is_alphabetic()) { + if word_lower.chars().all(|c| c.is_alphabetic()) { // Count consecutive repetitions (case-insensitive) let mut count = 1; while i + count < words.len() && words[i + count].to_lowercase() == word_lower { @@ -275,7 +274,7 @@ fn collapse_stutters(text: &str) -> String { /// /// This function cleans up raw transcription text by: /// 1. Removing filler words based on the app language (or custom list) -/// 2. Collapsing repeated 1-2 letter stutters (e.g., "wh wh wh" -> "wh") +/// 2. Collapsing repeated word stutters (e.g., "wh wh wh" -> "wh") /// 3. Cleaning up excess whitespace /// /// # Arguments @@ -425,6 +424,13 @@ mod tests { assert_eq!(result, "I think so"); } + #[test] + fn test_filter_stutter_longer_words() { + let text = "Check data doc doc doc doc documentation."; + let result = filter_transcription_output(text, "en", &None); + assert_eq!(result, "Check data doc documentation."); + } + #[test] fn test_filter_stutter_mixed_case() { let text = "No NO no NO no";