MCPcopy
hub / github.com/KittenML/KittenTTS / float_to_words

Function float_to_words

kittentts/preprocess.py:101–127  ·  view source on GitHub ↗

Convert a float (or numeric string) to words, reading decimal digits individually. Accepts a string to preserve trailing zeros (e.g. "1.50" → "one point five zero"). Examples: 3.14 → "three point one four" -0.5 → "negative zero point five" "3.10" → "three po

(value, decimal_sep: str = "point")

Source from the content-addressed store, hash-verified

99
100
101def float_to_words(value, decimal_sep: str = "point") -> str:
102 """
103 Convert a float (or numeric string) to words, reading decimal digits individually.
104 Accepts a string to preserve trailing zeros (e.g. "1.50""one point five zero").
105
106 Examples:
107 3.14 → "three point one four"
108 -0.5 → "negative zero point five"
109 "3.10""three point one zero"
110 1.007 → "one point zero zero seven"
111 """
112 text = value if isinstance(value, str) else f"{value}"
113 negative = text.startswith("-")
114 if negative:
115 text = text[1:]
116
117 if "." in text:
118 int_part, dec_part = text.split(".", 1)
119 int_words = number_to_words(int(int_part)) if int_part else "zero"
120 # Read each decimal digit individually; "0" → "zero"
121 digit_map = ["zero"] + _ONES[1:] # index 0 → "zero"
122 dec_words = " ".join(digit_map[int(d)] for d in dec_part)
123 result = f"{int_words} {decimal_sep} {dec_words}"
124 else:
125 result = number_to_words(int(text))
126
127 return f"negative {result}" if negative else result
128
129
130def roman_to_int(s: str) -> int:

Callers 2

_replaceFunction · 0.85
preprocess.pyFile · 0.85

Calls 1

number_to_wordsFunction · 0.85

Tested by

no test coverage detected