๐ End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[ensu] Keep spaces before numbers in voice transcripts
laurenspriem51756c93f121
diff --git a/rust/apps/ensu/changes/voice-transcript-spacing.md b/rust/apps/ensu/changes/voice-transcript-spacing.mdnew file mode 100644index 0000000000..c38f9b647a--- /dev/null+++ b/rust/apps/ensu/changes/voice-transcript-spacing.md@@ -0,0 +1 @@+- Fixed missing spaces before numbers, currency amounts and some non-English words in voice transcripts.diff --git a/rust/crates/ensu/src/transcription/parakeet.rs b/rust/crates/ensu/src/transcription/parakeet.rsindex 1fb161212d..997f7f4f80 100644--- a/rust/crates/ensu/src/transcription/parakeet.rs+++ b/rust/crates/ensu/src/transcription/parakeet.rs@@ -210,6 +210,7 @@ fn argmax(values: &[f32]) -> Result<usize> {fn render(emissions: &[Emission], vocabulary: &[String]) -> Transcript {let mut transcript = Transcript::default();+ let mut after_standalone_marker = false;for (index, emission) in emissions.iter().enumerate() {let piece = vocabulary[emission.token].replace('โ', " ");let start = emission.frame as f32 * FRAME_SECONDS;@@ -218,9 +219,14 @@ fn render(emissions: &[Emission], vocabulary: &[String]) -> Transcript {.map_or(start + 0.05, |next| next.frame as f32 * FRAME_SECONDS);transcript.text.push_str(&piece);if piece.trim().is_empty() {+ after_standalone_marker = true;continue;}- if piece.starts_with(' ') || transcript.words.is_empty() {+ let starts_word = piece.starts_with(' ')+ || transcript.words.is_empty()+ || (after_standalone_marker && !regex!(r"\A\p{P}").is_match(&piece));+ after_standalone_marker = false;+ if starts_word {transcript.words.push(TimedWord {text: piece.trim().to_owned(),start,@@ -326,9 +332,38 @@ mod tests {let vocabulary = vec!["โHello".into(), "โ".into(), "ไธ็".into(), "!".into()];let continuation = render(&emissions, &vocabulary);assert_eq!(continuation.text, "Hello ไธ็!");- assert_eq!(continuation.words.len(), 1);- assert_eq!(continuation.words[0].text, "Helloไธ็!");- assert_eq!(continuation.words[0].end, 7.0 * FRAME_SECONDS + 0.05 - 0.25);+ assert_eq!(continuation.words.len(), 2);+ assert_eq!(continuation.words[0].text, "Hello");+ assert_eq!(continuation.words[0].end, 5.0 * FRAME_SECONDS - 0.25);+ assert_eq!(continuation.words[1].text, "ไธ็!");+ assert_eq!(continuation.words[1].start, 6.0 * FRAME_SECONDS - 0.25);+ assert_eq!(continuation.words[1].end, 7.0 * FRAME_SECONDS + 0.05 - 0.25);+ }++ #[test]+ fn standalone_markers_start_words_unless_punctuation_follows() {+ let vocabulary = vec![+ "โat".into(),+ "โ".into(),+ "1".into(),+ "0".into(),+ "ั".into(),+ "$".into(),+ "5".into(),+ ",".into(),+ ];+ let tokens = [0, 1, 2, 3, 1, 4, 1, 5, 6, 1, 7];+ let emissions: Vec<_> = tokens+ .into_iter()+ .enumerate()+ .map(|(frame, token)| Emission { token, frame })+ .collect();+ let words: Vec<_> = render(&emissions, &vocabulary)+ .words+ .into_iter()+ .map(|word| word.text)+ .collect();+ assert_eq!(words, ["at", "10", "ั", "$5,"]);}#[test]