FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Fix TTS reading of prices with more than two decimal digits
NetterSilverd0750c1dc4bc
diff --git a/crates/tts-text/src/normalize.rs b/crates/tts-text/src/normalize.rsindex 3f15a8fa4..1378b7269 100644--- a/crates/tts-text/src/normalize.rs+++ b/crates/tts-text/src/normalize.rs@@ -348,9 +348,10 @@ fn parse_amount(rest: &str, _lang: Lang) -> Option<(u64, usize, usize, u32, boollet major = int_digits.parse::<u64>().ok()?;let had_minor = after_decimal && !frac_digits.is_empty();// One fractional digit denotes tenths of a major unit (e.g. $1.5 = $1.50),- // not five minor units. Preserve the existing two-digit and longer readings.+ // not five minor units. Digits beyond the second are sub-cent precision and are+ // dropped, so the minor part never exceeds 99 (`$3.459` reads as 45 cents).let minor = if had_minor {- let value = frac_digits.parse::<u32>().ok()?;+ let value = frac_digits.get(..2).unwrap_or(&frac_digits).parse::<u32>().ok()?;if frac_digits.len() == 1 { value * 10 } else { value }} else {0@@ -1236,6 +1237,16 @@ mod tests {assert_eq!(words("$0.50", Lang::EnUs), "zero dollars and fifty cents");}+ #[test]+ fn money_fraction_beyond_two_digits_is_not_hundreds_of_cents() {+ for lang in [Lang::EnUs, Lang::EnGb] {+ assert_eq!(words("gas is $3.459 a gallon", lang), "gas is three dollars and forty-five cents a gallon");+ assert_eq!(words("$1.999", lang), "one dollar and ninety-nine cents");+ assert_eq!(words("$1.250", lang), "one dollar and twenty-five cents");+ assert_eq!(words("$1.005", lang), "one dollar");+ }+ }+#[test]fn first_digit_group_keeps_leading_zeros() {for lang in [Lang::EnUs, Lang::EnGb] {