From 5fcb207a6085c7bafd3a0520dfe5a3d8f4ff2a79 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Fri, 13 Nov 2026 14:05:46 -0300 Subject: [PATCH] fix(normalizer): read money with more than two decimals as a decimal number Signed-off-by: Lucas Barros --- CHANGELOG.md | 1 + .../services/text_processing/normalization/english.py | 9 +++++++++ api/tests/test_normalizer.py | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d391016..28038852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Per-PR attribution and contributor credits are published automatically on the co ### Fixed - `GAP_TRIM_MS=0` turns the base chunk trim off. It used to slice every chunk to nothing, so all audio came back silent - Money with cents reads the whole part right: `-$1.50` is "minus one dollar and fifty cents" (was "minus two dollars"), and `$1.05` says "one dollar", not "one dollars" +- Money with more than two decimals is read as a decimal number: `$3.499` is "three point four nine nine dollars" (was "three dollars and four hundred and ninety-nine cents"), and `$0.0012` no longer becomes "twelve cents" - Non-streamed WAV (`"stream": false`) has its real length in the header. It said 4 GB, so readers that trust the header, like Python's `wave`, reported a one-sentence file as about 25 hours long (#586) ## [v0.10.0] - 2026-11-08: Websockets/Realtime API, CPU Memory & API Keys diff --git a/api/src/services/text_processing/normalization/english.py b/api/src/services/text_processing/normalization/english.py index 8802223b..d5f1ff17 100644 --- a/api/src/services/text_processing/normalization/english.py +++ b/api/src/services/text_processing/normalization/english.py @@ -320,6 +320,15 @@ def handle(m: re.Match[str]) -> str: whole = INFLECT_ENGINE.number_to_words(conditional_int(number)) return f"{whole}{multiplier} {bills}" + digits = m.group(3).replace(",", "") + if len(digits.partition(".")[2]) > 2: + # More than two decimals is not a cents amount ($3.499 a gallon, + # $0.0012 per token): read the decimal number, not 499 or 12 cents. + if digits.startswith("."): + digits = "0" + digits + whole = INFLECT_ENGINE.number_to_words(m.group(1) + digits) + return f"{whole} {bills}" + # Read the sign on its own: floor(-1.5) is -2, and int(-0.25) drops the minus. sign = "minus " if number < 0 else "" dollars = int(abs(number)) diff --git a/api/tests/test_normalizer.py b/api/tests/test_normalizer.py index 1da3a731..0ff0aedd 100644 --- a/api/tests/test_normalizer.py +++ b/api/tests/test_normalizer.py @@ -79,6 +79,11 @@ ("-$0.25", "minus zero dollars and twenty-five cents"), ("$1.05 each", "one dollar and five cents each"), ("€1.20", "one euro and twenty cents"), + # more than two decimals is a rate, not cents + ("Gas is $3.499 a gallon", "Gas is three point four nine nine dollars a gallon"), + ("$0.0012 per token", "zero point zero zero one two dollars per token"), + ("-$1.005", "minus one point zero zero five dollars"), + ("£2.000", "two pounds"), # issue #224 ( "still slated to lose $400 million.",