Skip to main content
Pre-release

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

tugaphone: dialect-aware Portuguese phonemizer

tugaphone turns Portuguese text into IPA, and it does it per Lusophone dialect. Give it a sentence and a dialect code, get back a phoneme string with stress marks.

O gato dorme.
pt-PT → ˈo ˈgatu ˈdɔɾmɨ
pt-BR → ˈu ˈgatʊ ˈdoɾmi
pt-AO → ˈʊ ˈgatʊ ˈdɔʁmɨ
pt-MZ → ˈu ˈgatu ˈdɔrme
pt-TL → ˈo ˈgatʊ ˈdɔrme

Under the hood it drives the orthography2ipa candidate lattice: a dialect is an orthography2ipa lect spec, and the spec's grapheme table, allophone rules and cross-word sandhi produce that dialect's phonology directly. tugaphone adds the stages orthography2ipa leaves to the caller: a phonetic lexicon, meaning-based homograph resolution, and gender- and scale-aware number expansion, wired through orthography2ipa's own extension points. See docs/architecture.md.


Install

pip install tugaphone

Its runtime dependencies (orthography2ipa, silabificador, tugalex, bifonia, unicode-rbnf) install automatically. The phonetic lexicon rides in through tugalex.


30-second quick start

from tugaphone import TugaPhonemizer

ph = TugaPhonemizer()
print(ph.phonemize_sentence("O gato dorme.", "pt-PT"))
# ˈo ˈgatu ˈdɔɾmɨ

Construct TugaPhonemizer() once, then call phonemize_sentence(text, lang) as often as you like. The result is a space-separated phoneme string, one token per word, with ˈ marking primary stress. lang selects the orthography2ipa lect spec, so it changes the phonology, not just the spelling.

Digits are best spelled out first, with gender agreement:

from tugaphone.number_utils import normalize_numbers

text = normalize_numbers("comprei 2 casas")   # 'comprei duas casas'
print(ph.phonemize_sentence(text, "pt-PT"))

Why tugaphone

Most Portuguese G2P you can reach for treats Portuguese as one or two varieties. tugaphone's reason to exist is dialect granularity: one API that spans the whole Lusophone space and, within European Portuguese, a set of sub-regional accents.

Tool Portuguese coverage Notes
espeak-ng pt (European) + pt-br (Brazilian) Small, fast, rule-based, about 100 languages, widely used as a TTS front-end. Two Portuguese varieties only, no African/Asian Lusophone, no sub-regional accents.
phonemizer (bootphon) via espeak-ng A backend wrapper, for Portuguese it delegates to espeak-ng, so the same two varieties. Needs the espeak binary.
Single-variety Portuguese toolkits (e.g. Brazilian-focused phonetic transcribers) one national variety Strong within their variety, not built to cover the full Lusophone range from one interface.
tugaphone 41 lects: five national standards + European, Brazilian, African, Asian and other varieties Pure Python, IPA output with stress, meaning-based homograph resolution, one API across the whole Lusophone space.

What tugaphone buys you over the coarse options:

  • 41 Portuguese-family lects reachable by BCP-47 code, the five national standards (pt-PT, pt-BR, pt-AO, pt-MZ, pt-TL) plus European and Brazilian sub-regional varieties and the African, Asian and other lects.
  • Meaning-based homograph resolution, sede thirst vs headquarters, gosto verb vs noun, via bifonia.
  • Gender- and scale-aware number expansion (long scale for pt-PT, short scale for pt-BR).
  • A phonology-accurate core, each dialect's sounds come from its orthography2ipa lect spec, not from a post-hoc string-edit layer.

Honest trade-offs: tugaphone is Portuguese-only and younger than espeak-ng, which covers far more languages and years of field use. Its accuracy against the per-lect gold is measured openly, see docs/benchmarking.md.


Features

Dialect coverage

The five national standards, plus European, Brazilian, African, Asian and other sub-regional lects, 41 codes in all, from list_dialects():

Code Region
pt-PT European Portuguese, heavy vowel reduction, post-alveolar fricatives, uvular /ʁ/
pt-BR Brazilian Portuguese, fuller vowels, /t d/ palatalisation, l-vocalisation
pt-AO Angolan Portuguese, moderate reduction, alveolar trill, Bantu substrate
pt-MZ Mozambican Portuguese, similar to European with regional variation
pt-TL Timorese Portuguese, conservative pronunciation, Tetum substrate
for code in ["pt-PT", "pt-BR", "pt-AO", "pt-MZ", "pt-TL"]:
    print(code, "→", ph.phonemize_sentence("Choveu muito ontem.", code))
# pt-PT → ʃuˈvew ˈmũjtu ˈõtɐ̃j
# pt-BR → ʃoˈvew ˈmwĩtʊ ˈõtẽj
# pt-AO → ʃoˈvew ˈmũjntʊ ˈõntẽj
# pt-MZ → ʃoˈvew ˈmũjtu ˈõtẽj
# pt-TL → ʃoˈvew ˈmujtʊ ˈõntɐ̃j

The European sub-regional lects (pt-PT-x-porto, -braga, -trasosmontes, -madeira, -acores, …), the Brazilian ones (pt-BR-x-sp, -rj, -caipira, -bahia, …) and the rest are all reachable the same way. See docs/dialects.md for the full list and the legacy aliases.

Homograph disambiguation

Heterophonic homographs are resolved by meaning via bifonia: sede thirst vs headquarters, forma mould vs shape, gosto noun vs verb. bifonia inserts open/closed-vowel diacritics during the pipeline's normalization stage, before the lattice transcribes the sentence, so the same spelling maps to different pronunciations depending on sentence context.

print(ph.phonemize_sentence("Eu gosto de música."))   # verb → ˈew ˈɡɔʃtu ˈdɨ ˈmuzikɐ
print(ph.phonemize_sentence("Tenho bom gosto."))       # noun → ˈtɛɲu ˈbõ ˈɡoʃtu

Sub-regional accents

Sub-regional accents are lects like any other, select one by its BCP-47 private-use code. Its phonology (betacism, rising diphthongs, palatalization, /u/ fronting, coda-sibilant sandhi, …) is encoded in the orthography2ipa lect spec, so no extra argument is needed:

# Porto: rising diphthongs, betacism (/v/ → [b])
print(ph.phonemize_sentence("O vinho é muito bom.", "pt-PT-x-porto"))
# ˈwo ˈbiɲu ˈjɛ ˈmujtu ˈbõ

# Trás-os-Montes: <ch> → [tʃ], betacism
print(ph.phonemize_sentence("A chave.", "pt-PT-x-trasosmontes"))
# ˈɐ ˈtʃabɨ

from tugaphone import list_dialects
print(list_dialects())   # all 41 registered lect codes

Legacy tugaphone accent codes resolve as aliases (pt-PT-x-azores → pt-PT-x-acores, pt-BR-x-sao-paulo → pt-BR-x-sp, …). See docs/dialects.md.

Forcing an accent for a TTS

Selecting a lect describes an accent, force_accent forces one into a downstream voice. For a phoneme-input TTS (phoonnx-style) that is the target IPA, for a grapheme-input TTS (a fixed pt-PT voice) it is Portuguese text respelled so the base voice reads it as the target sounds, feed a pt-PT voice binho to force the Northern betacism of vinho.

from tugaphone import force_accent

# phoneme-input TTS: the target accent's IPA
force_accent("o vinho verde", "pt-PT-x-porto", mode="ipa")
# 'o ˈbiɲu ˈbjɛɾd'

# grapheme-input pt-PT TTS: respelled text it will pronounce with the accent
force_accent("o vinho verde", "pt-PT-x-porto", mode="respell", base_lect="pt-PT")
# 'o binho berde'

The respeller is verification-gated (an edit is kept only if it moves the base voice's own reading toward the target), so it never makes a word worse and leaves unspellable contrasts alone. Ad-hoc per-voice tweaks live in a JSON-serialisable AccentOverlay, and examples/12_synthetic_corpus.py generates a parallel (sentence, lect, ipa, respelled_text) training corpus. See docs/accent_forcing.md.

Number normalization

Digits are spelled out with gender agreement and long/short scale per dialect:

from tugaphone.number_utils import normalize_numbers

normalize_numbers("vou comprar 1 casa")   # 'vou comprar uma casa'
normalize_numbers("vou adotar 1 cão")     # 'vou adotar um cão'
normalize_numbers("comprei 2 casas")      # 'comprei duas casas'

Syllabification and stress

Stress and the dialect's phonology come from the orthography2ipa lect spec, syllabification is supplied by silabificador, wired in as orthography2ipa's syllabify plugin.

orthography2ipa plugin interface

TugaphoneG2PPlugin implements the orthography2ipa G2P plugin interface (transcribe, transcribe_word, language_codes), so a framework that loads phonemizers through that interface can drive tugaphone:

from tugaphone.plugin import TugaphoneG2PPlugin

p = TugaphoneG2PPlugin(lang="pt-BR")
print(p.transcribe("o gato dorme"))   # ˈu ˈgatʊ ˈdoɾmi

Architecture: relationship to orthography2ipa

tugaphone phonemizes by driving the shared o2i candidate lattice. A dialect is an o2i lect spec: phonemize_sentence(text, lang) resolves lang to a lect code and runs orthography2ipa.G2P(lect).transcribe(text). The spec's grapheme table, allophone_rules and cross-word sandhi_rules produce the dialect's phonology, including genuinely cross-word processes like coda-sibilant voicing sandhi, with no string-transform pass after transcription.

tugaphone contributes only the stages o2i leaves to the caller, wired through o2i's own extension points:

Concern Owner
Base phonology, dialect phenomena, sandhi, stress orthography2ipa lect spec
Number / ordinal verbalization tugaphone (number_utils, via the normalize stage)
Sense-based homograph marking tugaphone (bifonia, via the normalize stage)
Curated pronunciation lexicon tugaphone (tugalex, via register_lexicon)
Syllabification tugaphone (silabificador, via the syllabify plugin)

The lexicon overlay applies only to the lects whose lexical tradition matches a tugalex region (pt-PT/pt-PT-x-lisbon, pt-BR/pt-BR-x-rj, pt-BR-x-sp, pt-AO, pt-MZ, pt-TL), every other lect is pure lattice.

tugaphone.tokenizer and tugaphone.dialects remain as a token-tree linguistic feature API (manner, place, voicing, syllable roles, CV skeletons) and the rules-only benchmark baseline, not the phonemization path. See docs/architecture.md and docs/tokenizer.md.


Sibling libraries

tugaphone is part of the TigreGotico Portuguese NLP stack:

Library Role
tugalex Phonetic lexicon
silabificador Syllabifier
bifonia Heterophone sense disambiguation
orthography2ipa The candidate lattice and the Portuguese lect specs

Documentation


License

Apache License 2.0. See LICENSE.

Metadata

Release files for tugaphone 1.2.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 tugaphone 1.2.2a1
File Size Uploaded
tugaphone-1.2.2a1.tar.gz 264.9 kB Details

Built distribution (wheel)

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

Total release size: 510.0 kB

Release files / tugaphone-1.2.2a1.tar.gz

Download URL tugaphone-1.2.2a1.tar.gz
Size 264.9 kB
Tags Source
SHA-256 checksum
How to use checksums
96da04febf73e020630b34a5da9f601c9c535564671539ba6ebb599e392d5fe7
BLAKE2b-256 checksum
How to use checksums
d637ea60390cd41c9f3bfa82db36c8889e321c57dc1652cd99c8dfc9b3e3ba34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / tugaphone-1.2.2a1-py3-none-any.whl

Download URL tugaphone-1.2.2a1-py3-none-any.whl
Size 245.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f0e44f0aefab564bb06a70017a51829e19aebc495ba694adf468f25d7e8610e
BLAKE2b-256 checksum
How to use checksums
4b3d5066d79dbe8ad103fe0f56236fe494602a446c81cbdb2dfe6edb2a5a064e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

1.2.2a1 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.0.2

2 release files

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