hex/src/spoken_text.rs
Kit Langton 04a42dae3d refactor: consolidate settings commits, transcription padding, and SDK framing
Settings controls commit a full candidate before changing the saved UI choice,
so a failed write keeps shortcut capture open and preserves pending debounced
edits. The macOS Transcriber owns backend input padding for ordinary,
voice-protocol, and segmented transcription. Moonshine stream cleanup and the
Linux client share one owner-side path. The command SDK shares capture
normalization between constructors and host registration, and the public SDK
decodes model progress and dictation levels with one bounded SSE framer. The
signing scripts share one identity helper, and historical release evidence
moves out of the feature map.
2026-09-22 17:08:43 -07:00

38 lines
1.3 KiB
Rust

pub(crate) fn normalize(text: &str) -> String {
text.split_whitespace()
.filter_map(|word| {
let word = word.trim_matches(|character: char| character.is_ascii_punctuation());
if word.is_empty() {
return None;
}
let word = word.to_ascii_lowercase();
Some(match word.as_str() {
"zero" => "0".to_string(),
"one" => "1".to_string(),
"two" => "2".to_string(),
"three" => "3".to_string(),
"four" => "4".to_string(),
"five" => "5".to_string(),
"six" => "6".to_string(),
"seven" => "7".to_string(),
"eight" => "8".to_string(),
"nine" => "9".to_string(),
_ => word,
})
})
.collect::<Vec<_>>()
.join(" ")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn normalizes_spoken_numbers_and_punctuation() {
assert_eq!(normalize("Move LEFT, three!"), "move left 3");
// Match the command SDK constructor/host parity fixture: non-ASCII
// aliases remain distinct while ASCII case and spoken digits fold.
assert_eq!(normalize("Ä ä A a ONE one"), "Ä ä a a 1 1");
}
}