"""Phone-agent number reading for Voxi-Lite (Mithi), applied to the text BEFORE Mithi's own normaliser. Mithi's normaliser reads numbers like a news reader and has gaps for a phone agent (laptop check, 2026-11-08): ₹1,250 -> "एक हजार दो सौ पचास" (agents say "बारह सौ पचास"), 10:30 -> "दस बजकर तीस मिनट" (agents say "साढ़े दस"), phone numbers with a comma after every digit (choppy), and a plain 100000 read digit by digit. This front end writes the spoken words itself, so Mithi's normaliser has nothing left to change: hi money (₹, Rs, रुपये; lakh / crore; paise; 2.5 lakh -> ढाई लाख), times (सवा / साढ़े / पौने, बजकर ... मिनट), dates (31/12/2027), digit strings (phone numbers in 5+5 or as written, OTP / PIN / IDs in groups of 3), other numbers as Indian-system cardinals (हज़ार, लाख, करोड़); 1,100-9,999 amounts in the agent style "बारह सौ". ta digit strings only (phone, OTP, IDs) in groups; everything else is left to Mithi / Maya's normaliser, which reads Tamil numbers well in our tests. Groups are separated by ", " (a short pause); digits inside a group by spaces. from numbers_front import speak speak("आपका बिल ₹1,250 है।", "hi") -> "आपका बिल बारह सौ पचास रुपये है।" """ import re HI = ("शून्य एक दो तीन चार पाँच छह सात आठ नौ दस ग्यारह बारह तेरह चौदह पंद्रह सोलह सत्रह अठारह उन्नीस बीस इक्कीस बाईस " "तेईस चौबीस पच्चीस छब्बीस सत्ताईस अट्ठाईस उनतीस तीस इकतीस बत्तीस तैंतीस चौंतीस पैंतीस छत्तीस सैंतीस अड़तीस " "उनतालीस चालीस इकतालीस बयालीस तैंतालीस चौवालीस पैंतालीस छियालीस सैंतालीस अड़तालीस उनचास पचास इक्यावन बावन " "तिरपन चौवन पचपन छप्पन सत्तावन अट्ठावन उनसठ साठ इकसठ बासठ तिरसठ चौंसठ पैंसठ छियासठ सड़सठ अड़सठ उनहत्तर सत्तर " "इकहत्तर बहत्तर तिहत्तर चौहत्तर पचहत्तर छिहत्तर सतहत्तर अठहत्तर उन्यासी अस्सी इक्यासी बयासी तिरासी चौरासी " "पचासी छियासी सत्तासी अट्ठासी नवासी नब्बे इक्यानवे बानवे तिरानवे चौरानवे पंचानवे छियानवे सत्तानवे अट्ठानवे " "निन्यानवे").split() assert len(HI) == 100 TA_DIGITS = "பூஜ்ஜியம் ஒன்று இரண்டு மூன்று நான்கு ஐந்து ஆறு ஏழு எட்டு ஒன்பது".split() HI_MONTHS = ["जनवरी", "फ़रवरी", "मार्च", "अप्रैल", "मई", "जून", "जुलाई", "अगस्त", "सितंबर", "अक्टूबर", "नवंबर", "दिसंबर"] HALF = {1: "डेढ़", 2: "ढाई"} # 1.5, 2.5; from 3 on: साढ़े तीन ... def hi_num(n, agent=False): """Indian-system cardinal. agent=True: 1,100-1,999 with a non-zero hundreds digit as "बारह सौ पचास" (agents say "बारह सौ", never "उनचास सौ").""" n = int(n) if n < 100: return HI[n] if agent and 1100 <= n <= 1999 and (n // 100) % 10: rest = n % 100 return f"{HI[n // 100]} सौ" + (f" {HI[rest]}" if rest else "") parts = [] for unit, word in ((10 ** 7, "करोड़"), (10 ** 5, "लाख"), (1000, "हज़ार"), (100, "सौ")): if n >= unit: q, n = divmod(n, unit) parts.append(f"{hi_num(q)} {word}") if n: parts.append(HI[n]) return " ".join(parts) def hi_fraction(x): """2.5 -> ढाई, 1.5 -> डेढ़, 3.5 -> साढ़े तीन, 2.25 -> सवा दो, 2.75 -> पौने तीन; other decimals with दशमलव.""" whole, frac = int(x), round(x - int(x), 2) if frac == 0: return hi_num(whole) if frac == 0.5 and whole in HALF: return HALF[whole] if frac == 0.5 and whole >= 3: return f"साढ़े {hi_num(whole)}" if frac == 0.25 and whole >= 1: return f"सवा {hi_num(whole)}" if frac == 0.75 and whole >= 1: return f"पौने {hi_num(whole + 1)}" s = f"{x}".split(".")[1] return f"{hi_num(whole)} दशमलव " + " ".join(HI[int(d)] for d in s) def digits(s, lang, group=None): """A digit string read digit by digit, in groups: as written (spaces / hyphens), else of size `group`.""" words = HI if lang == "hi" else TA_DIGITS return ", ".join(" ".join(words[int(d)] for d in p) for p in group_digits(s, group)) def group_digits(s, group=None): """'98765 43210' -> ['98765', '43210']; '7730214' (group 3) -> ['773', '02', '14'].""" parts = [p for p in re.split(r"[\s\-]+", s.strip()) if p] if len(parts) == 1 and group: p = parts[0] if len(p) == 10 and group == 5: parts = [p[:5], p[5:]] else: # groups of `group`; never a lone last digit (4 -> 2+2, 7 -> 3+2+2) sizes = [group] * (len(p) // group) + ([len(p) % group] if len(p) % group else []) if len(sizes) > 1 and sizes[-1] == 1: sizes[-2:] = [sizes[-2] - 1, 2] if sizes[-2] > 2 else [sizes[-2] + 1] if len(sizes) == 1 and len(p) == 4 and group == 3: sizes = [2, 2] parts, i = [], 0 for n in sizes: parts.append(p[i:i + n]); i += n return parts def hi_time(h, m): h, m = int(h), int(m) h12 = h % 12 or 12 nxt = h12 % 12 + 1 if m == 0: return hi_num(h12) if m == 30: return HALF.get(h12, f"साढ़े {hi_num(h12)}") if m == 15: return f"सवा {hi_num(h12)}" if m == 45: return f"पौने {hi_num(nxt)}" return f"{hi_num(h12)} बजकर {hi_num(m)} मिनट" ID_WORDS_HI = r"(?:OTP|ओ ?टी ?पी|PIN|पिन|आईडी|ID|नंबर|नम्बर|कोड|संख्या|ऑर्डर|टोकन|पॉलिसी|खाता|अकाउंट|रेफ़रेंस|रेफरेंस|ट्रैकिंग|अंक)" ID_WORDS_TA = r"(?:OTP|PIN|எண்|நம்பர்|ஐடி|ID|கோட்|கோடு|குறியீடு|ஆர்டர்|டோக்கன்|பாலிசி|கணக்கு)" ALNUM = r"\b([A-Z]{1,4})-?(\d{2,})\b" # no space: "EMI 12 महीने" is not an ID # AB4521 -> "A B, four five two one" (letters, then digits) PHONE = r"(?