Skip to content

About

Respell English words in Twi orthography so a Twi G2P can pronounce them

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

en-twi-pronouncer

Respell English words in Twi orthography, so that a Twi grapheme-to-phoneme converter can pronounce them — and a Twi-only speech system can read text containing English.

computer   -> kɔmputa      -> kʰ ɔ m pʰ u tʰ a
school     -> sukuu        -> s u kʰ u u
election   -> elɛhyɛn      -> e l ɛ ç ɛ n
university -> yunibɛsiti   -> j u n ɪ b ɛ s ɪ tʰ ɪ
hospital   -> asɔpiti      -> a s ɔ pʰ ɪ tʰ ɪ

These are the established borrowing forms, not naive transliteration: v→b, -tion→hy (which is /ç/, a genuinely Twi sound), and hospital lands on asɔpiti, which is what Twi speakers actually say.

pip install en-twi-pronouncer
twi-adapt word computer school election
twi-adapt adapt --text "Mepɛ sɛ mesua computer science wɔ university hɔ." --report
from twi_adapt import Lexicon, adapt_text

lex = Lexicon.load()
print(adapt_text("Ɔkyerɛkyerɛni no kaa sɛ the examination bɛba next week.", lex).text)
# Ɔkyerɛkyerɛni no kaa sɛ de ɛksaminɛhyɛn bɛba nɛkisiti wiik.

Why respell instead of code-switch?

For text-to-speech there are two ways to handle an English word inside Twi:

how needs
code-switch pronounce it as English a bilingual model that has learned English phonemes (θ æ ɹ eɪ)
adapt (this) respell it in Twi and pronounce it as Twi a Twi-only model

Adaptation is often the better trade. A bilingual model has to learn a second phoneme inventory from far less data, and it entangles voice with language. Adaptation sidesteps that entirely: verified over a full code-switched sentence, every adapted word phonemises into pure Twi phonemes — 65 units, none outside a Twi-only model's inventory. It also matches how Ghanaians actually speak: sukuu, asɔpiti and pɔlisi are how these words are said in Twi, not accented English.

The trade-off is honest: adaptation gives you Twi pronunciation of an English word, which is right for established loanwords and wrong if you specifically wanted English pronunciation.

The alphabet is the constraint

Akan has 22 letters and no c, j, q, v, x or z. That is why loanwords shift. The digraphs matter as much: ky gy hy hw kw tw dw ny nw each spell one sound.

Every generated form is validated against that alphabet and against Twi phonotactics. An LLM will occasionally return a spelling containing a v or a z; a downstream G2P would then mispronounce or silently drop it. So generation is never trusted — invalid forms are retried once, then rejected and left to the rules. Of 39,749 words, 57 (0.14%) failed validation.

Offline by design

Adaptation quality comes from a model, but that model runs once, at build time. What ships is a lookup table plus deterministic rules:

  1. lexicon — a curated, validated form (preferred)
  2. rules — deterministic respelling for a word nobody adapted yet
  3. unchanged — with --strict, leave the word alone rather than guess

So a TTS server, a phone or an offline batch job needs no API key and no network.

Which words get adapted

Two signals, because neither suffices alone:

  • illegal letters — victory, zone, project cannot be Twi. Precise but incomplete.
  • lexicon presence — bank, pilot, radio are spelled with Twi letters only, so a letter test passes them through untouched even though they are English.

Anything neither flags is left alone, which is the safe default: a real Twi word must never be mangled. Words that slip through are listed in the report, so you extend the lexicon rather than being surprised.

Building your own lexicon

The shipped lexicon covers 39,692 words from ghananlpcommunity/ghana-named-entities — 253,395 Ghanaian named entities split into words and ranked by frequency, so a truncated build still covers most running text.

python tools/words_from_named_entities.py --out data/words.tsv --min-count 2
export GEMINI_API_KEY=...
twi-adapt build --words data/words.tsv --out data/lexicon.json --batch 400 --concurrency 16

Batches are independent and run concurrently — ~59 words/s at 16 in flight, so 40k words takes about 11 minutes. Progress is checkpointed and build resumes, which matters: a schema hiccup 20k words in cost nothing.

Beyond TTS

The lexicon is a pronunciation resource, not a TTS detail. It is equally usable for ASR lexicons, spelling normalisation of Twi text containing English, and loanword phonology research. Published as data under ghanaopendata and ghananlpcommunity.

Limits

  • Adapted forms are conventional, not unique. Twi speakers vary; government may be gabɛnmɛnt or gɔmɛnte. The lexicon records one form.
  • Rule-based fallback is cruder than the lexicon. It cannot know school is sukuu. Use --strict where a wrong pronunciation is worse than an unadapted word.
  • Some forms end in consonants (wiik, ɔf), which is un-Twi but still legally spelled and readable by a Twi G2P.
  • Asante Twi only. Other Akan varieties differ in orthography and would need their own pass.

Licence

MIT. The lexicon derives from ghana-named-entities (GhanaNLP Community); adaptations were generated with Gemini and validated automatically.

About

Respell English words in Twi orthography so a Twi G2P can pronounce them

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages