Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

text2spoken

text2spoken rewrites written text into the words a voice speaks. It expands numbers, dates, times, units, titles and contractions. A phonemizer then reads words, not digits or symbols.

Quickstart

pip install --pre text2spoken
from text2spoken import normalize

print(normalize("Dr. Smith paid 3/4 of the bill at 25°C.", "en"))
print(normalize("O Sr. Silva pagou 10kg às 14h30.", "pt-PT"))
Doctor Smith paid three quarters of the bill at twenty five degrees celsius.
O Senhor Silva pagou dez quilogramas às catorze e trinta.

Where this fits

Alone: it turns written text into spoken words, with from text2spoken import normalize. In the stack: it is the normalisation stage. A frontend or a TTS library calls it before phonemization, and it calls ovos-number-parser, ovos-date-parser and unicode_rbnf. Through scriptconv: scriptconv has no normalize extra. Install text2spoken directly.

What normalize does

normalize(text, lang) runs four passes in this order:

  1. It expands dates and times, such as 03/08/2025 and 14h30.
  2. It splits a word from a digit that a hyphen joins, such as sub-23. A range such as 3-2 stays as it is.
  3. It expands units and ordinal indicators, such as 10kg, 25°C and 1º.
  4. It reads each word, and expands contractions, titles, fractions and numbers.

Each pass is also a plain function, so a frontend can compose them and add its own rules. See docs/api.md.

The language tag selects the rules. The tables use the part before the first hyphen, so pt-BR and pt-PT share one table. en-US reads an ambiguous date as month first, and every other tag reads it as day first.

Languages

These languages have tables in text2spoken/tables.py:

Table Languages
CONTRACTIONS en
TITLES ca, de, en, es, fr, gl, it, nl, pt
UNITS de, en, es, fr, pt

This command prints the same list from the installed package:

python -c "from text2spoken import CONTRACTIONS, TITLES, UNITS; [print(sorted(t)) for t in (CONTRACTIONS, TITLES, UNITS)]"

Numbers, dates and times come from ovos-number-parser and ovos-date-parser, so those packages set their language coverage.

To add a language, add its entries to text2spoken/tables.py. A new language needs no code change.

Behaviour to know

  • The library uses no network and loads no model, so it works offline.
  • A language that the parsers do not support keeps its digits. The library logs an error and returns the text.
  • A text or lang value of the wrong type raises TypeError or AttributeError from the code that reads it.
  • Importing the library imports ovos-date-parser, which sets the import time.
  • ovos-config, a dependency of ovos-date-parser, creates ~/.config/mycroft at import.

Development

uv pip install --prerelease=allow -e ".[test]"
pytest tests

Licence

Apache-2.0. See LICENSE.

Metadata

Release files for text2spoken 0.0.2a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for text2spoken 0.0.2a1
File Size Uploaded Provenance Actions
text2spoken-0.0.2a1.tar.gz 25.7 kB Without provenance Details for text2spoken-0.0.2a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for text2spoken 0.0.2a1
File Interpreter ABI Platform Actions
text2spoken-0.0.2a1-py3-none-any.whl Python 3 none any Details for text2spoken-0.0.2a1-py3-none-any.whl

Total release size: 43.4 kB

Release files / text2spoken-0.0.2a1.tar.gz

Download URL text2spoken-0.0.2a1.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5ae12ef1559586b6c00bdb47ce988a09825116bb1940373ce6876c5ea86abb99
BLAKE2b-256 checksum
How to use checksums
e10937eed026d2f6aa39ab4fffc71a126d3943bfeabcc3decbcb34f05690aad6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / text2spoken-0.0.2a1-py3-none-any.whl

Download URL text2spoken-0.0.2a1-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92bc40ce9d553885495e7331ab267e91e445c982960992c86178806f9c86f517
BLAKE2b-256 checksum
How to use checksums
aeb0f39b600a59d009497b54d9b5923f4716b6d90ecbf671f9bd808d47646d52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for text2spoken 0.0.2a1

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.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page