Skip to content

armgit / Handy

Public Imported from GitHub
0

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

[bugfix] remove long repeating words (#976)

Alexander Yastrebov075fb5f78dad
diff --git a/src-tauri/src/audio_toolkit/text.rs b/src-tauri/src/audio_toolkit/text.rs
index 29f43ffe..2cd31718 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<Regex> = 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";