This release is a pre-release and may not be stable for production use.
OVOS Number Parser
ovos-number-parser turns spoken numbers into digits and digits into spoken
words, in 40 languages. It needs no voice assistant.
"two thousand twenty three" → 2023 → "two thousand, twenty three"
Words to digits (extract_number, numbers_to_digits) serves speech
recognition output and number extraction. Digits to words (pronounce_number,
pronounce_ordinal, pronounce_fraction) prepares text for speech synthesis.
numtag reads the words in all 40
languages. The pronounce_* and nice_number_* writers live in this package.
Install
uv pip install ovos-number-parser
Quick start
Each call takes a text or a number and a language code. The comment after
print shows the real output.
from ovos_number_parser import pronounce_number, pronounce_ordinal, extract_number, numbers_to_digits, is_fractional, is_ordinal
# digits -> words
print(pronounce_number(3.5, "en")) # three point five
print(pronounce_number(2023, "en")) # two thousand, twenty three
print(pronounce_ordinal(21, "en")) # twenty-first
# words -> digits
print(extract_number("three point five liters", "en")) # 3.5
print(extract_number("dos mil veintitrés", "es")) # 2023
print(numbers_to_digits("set a timer for five minutes", "en")) # set a timer for 5 minutes
# classification helpers
print(is_fractional("half", "en")) # 0.5
print(is_ordinal("third", "en")) # 3
# no number in the text -> False
print(extract_number("hello world", "en")) # False
Pass another language code and the same calls work. A code with a region
(pt-BR, pt-PT) reads the language of the tag, and the region where the language has regional forms.
Uses
Four common uses each have a runnable script in examples/.
ASR post-processing
Speech to text writes numbers as words. Most downstream systems want digits
(examples/asr_itn.py).
from ovos_number_parser import numbers_to_digits, extract_number
print(numbers_to_digits("i need twenty three of them", "en")) # i need 23 of them
print(extract_number("three point five liters", "en")) # 3.5
TTS normalization
Write numbers as words before synthesis, so the voice says "one thousand"
and not "one two three four dot five six"
(examples/tts_normalization.py).
from ovos_number_parser import pronounce_number
print(pronounce_number(1234.56, "en", places=2)) # one thousand, two hundred and thirty four point five six
print(pronounce_number(-3.5, "en")) # minus three point five
Numeric entity extraction
Pull cardinal, ordinal and fractional mentions out of free text without an ML
model (examples/ner.py).
from ovos_number_parser import extract_number, is_fractional, is_ordinal
print(extract_number("shipped in three boxes", "en")) # 3
print(is_ordinal("second", "en")) # 2
print(is_fractional("a quarter", "en")) # 0.25
With ordinals=True, a line that holds several numbers with other words
between them answers with the number written first. That number can be an
ordinal or a cardinal: extract_number("zwei von dem dritten", "de", ordinals=True) is 2. Two adjacent number words are how a fraction is
written, so they keep the reading of the language.
Multilingual round trips
The same functions cover 40 languages
(examples/multilingual.py).
In an OVOS skill and standalone
The API is the same in both cases. Only the source of the language code differs. A standalone program passes the code itself. A skill passes the session language.
# Standalone Python
from ovos_number_parser import extract_number
n = extract_number(text, "en")
# Inside an OVOS skill
class MySkill(OVOSSkill):
def handle_intent(self, message):
n = extract_number(message.data["utterance"], self.lang)
Supported languages
The 40 language codes are:
an ar ast az bg ca cs da de el en es et eu fa fi fr fy gl he hr hu id it kab ms mwl nb nl nn oc pl pt ro ru sk sl sv tr uk
Every language supports every public function (see Full function parity). numtag reads all of them. The language table lists the codes and the rules of single languages.
Grammatical gender
A language whose numerals inflect accepts a gender argument.
from ovos_number_parser import pronounce_number
from ovos_number_parser.util import GrammaticalGender
print(pronounce_number(2, "pt", gender=GrammaticalGender.FEMININE)) # duas
Documentation
The documentation index lists every page.
- API reference: every public function, the engine that answers it and its parameters
- Language notes: the rules of single languages and the known limits
- Adding a language: the steps for reading and speaking
- examples/: runnable scripts
- AGENTS.md: the guide for agents that change this repository
Related projects
- ovos-date-parser: dates and times
- ovos-lang-parser: languages
- ovos-color-parser: colors
License
Apache License 2.0.
Metadata
Release files for ovos-number-parser 0.31.4a10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ovos_number_parser-0.31.4a10.tar.gz | 475.0 kB | Without provenance | Details for ovos_number_parser-0.31.4a10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ovos_number_parser-0.31.4a10-py3-none-any.whl | Python 3 | none | any | Details for ovos_number_parser-0.31.4a10-py3-none-any.whl |
Total release size: 720.0 kB
Release files / ovos_number_parser-0.31.4a10.tar.gz
| Download URL | ovos_number_parser-0.31.4a10.tar.gz |
|---|---|
| Size | 475.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc59142c4cf1040515820fc099b7ae5dd1d9cb193dfe02680d7c43f9fc6bcd26
|
|
BLAKE2b-256 checksum How to use checksums |
ff002e719a42dcb673d53e12f0b2f64bdc11c47bbd2b84eb2757b6b32fdcc86c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / ovos_number_parser-0.31.4a10-py3-none-any.whl
| Download URL | ovos_number_parser-0.31.4a10-py3-none-any.whl |
|---|---|
| Size | 245.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
845a2d79c8f69d0d56dd54eb784b4fd1b8a6e85e90b08c86f9bfa069d8080dbd
|
|
BLAKE2b-256 checksum How to use checksums |
836f69005ad623bbe841694cec9b431da66d3a79dea86212f0ac3194096f0dcb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for ovos-number-parser 0.31.4a10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.