ghana-g2p
Grapheme-to-phoneme conversion for Ghanaian languages, built on africa-g2p.
africa-g2p covers 400+ African languages from a single general registry. ghana-g2p
narrows that to the languages actually spoken in Ghana and fixes what breaks when you
run real Ghanaian text through it: missing rule sets, Unicode codepoint variants, and
a handful of incorrect or incomplete mappings.
from ghana_g2p import GhanaG2P
tw = GhanaG2P("Asante Twi")
tw.ipa("Mfiase no Onyankopɔn bɔɔ ɔsoro.") # 'mfiasenooɲankʰopʰɔnbɔɔɔsoɾo'
tw.grapheme("Mfiase no Onyankopɔn bɔɔ ɔsoro.") # 'mfiasenoonyankopɔnbɔɔɔsoro'
tw.ipa("Akwaaba", sep=" ") # 'a kʷ a a b a'
Install
pip install ghana-g2p
That pulls africa-g2p, whose rule tables this builds on. Nothing else is needed — both are pure Python with no other runtime dependencies.
For development:
git clone https://github.com/GhanaNLP/ghana-g2p
cd ghana-g2p
pip install -e .
Why this exists
Running the full ghana-speech corpus through africa-g2p surfaced three classes of problem. Each is fixed here, and every fix is recorded as data you can inspect rather than hidden in code.
1. Ten Ghanaian languages have no rules at all. Birifor, Buli, Konni, Lelemi, Ntrubo, Sehwi, Sekpele, Selee, Tampulma and Tuwuli are simply absent. Each is mapped to a related language chosen by linguistic classification first, then measured orthographic coverage — never by character overlap alone, which ranks a Mande language above Dagaare for Birifor purely because they share the Latin alphabet.
2. Codepoint variants. Ghanaian orthographies write the same vowel with different
Unicode characters. Birifor and Tem spell /ʊ/ as ʊ (U+028A); the matching rule sets use
ʋ (U+028B). Tumulung Sisaala writes ɩ ʋ where the ssl rules expect ɪ ʊ. Normalising
these lifts Tem from 0.97 to full coverage and Sisaala from 0.80 to 1.00.
3. Incomplete and incorrect rule sets. The naw rules contain no p; bud has no e
or o; ada has no h or r. Ewe's rules map orthographic <y> to IPA y — a front
rounded vowel — where it is the palatal glide /j/, as it is in every other language in the
set. Missing letters are filled from a patch table of conventional Ghanaian readings; the
Ewe error is corrected outright.
Provenance is part of the output
A donor language gives plausible phonemes, not authoritative ones. Every result says where its rules came from, so you can filter on it rather than guess:
r = GhanaG2P("Sehwi").convert("kɔ ekyi")
r.phonemes # the phonemes
r.tier # 'donor'
r.rules # 'any' (Anyin — closely related Bia language)
r.is_donor # True
r.dropped # characters no rule could resolve
Tiers are:
| tier | meaning |
|---|---|
native |
the language's own africa-g2p rules |
equivalent |
the same language under a different code (Dagaare is dgd; Deg is mfi) |
donor |
a related language's rules, because africa-g2p has none for this one |
GhanaG2P(...).info carries the family, measured coverage, and a note explaining each
non-native choice.
Languages
42 languages. Names, ISO codes, common alternates and ghana-speech config names all
resolve to the same entry, so you don't have to know the ISO code:
GhanaG2P("Asante Twi") # by name
GhanaG2P("twi") # by code
GhanaG2P("Akuapem_Twi_twi") # by ghana-speech config name
GhanaG2P("Frafra") # by common alternate -> gur (Ninkare)
ghana-g2p --list # every language, donors marked
ghana-g2p --info Sehwi # provenance for one language
Donor mappings
| Language | Rules used | Coverage | Basis |
|---|---|---|---|
| Southern Birifor | Dagaare dgd |
1.00 | dialect continuum; ʊ→ʋ normalised |
| Buli | Dagaare dgd |
1.00 | Gur / Oti-Volta |
| Konni | Dagaare dgd |
1.00 | Buli-Konni branch, as Buli |
| Ntrubo | Kabiye kbp |
1.00 | neighbouring Gur language |
| Tampulma | Kasem xsm |
1.00 | Grusi branch |
| Lelemi | Avatime avn |
1.00 | GTM; Siwu is closer but drops ƒ |
| Sekpele | Ewe ewe |
1.00 | only donor covering ǝ |
| Selee | Siwu akp |
1.00 | Na-Togo branch |
| Tuwuli | Avatime avn |
1.00 | Ka-Togo branch |
| Sehwi | Anyin any |
1.00 | Central Tano / Bia |
Nawuri, Dangme and Bassar also use donors — not for lack of rules, but because their own
rule sets are missing core letters (p, h/r, and e/o respectively). They map to
Nkonya, Ga and Tem, each within the correct family.
Output format
ipa() and grapheme() strip punctuation and whitespace. By default units run together;
pass sep=" " to keep the boundaries.
Use sep=" " unless you have a reason not to. Many units are more than one character —
ny kp gb nw kʰ k͡p — so the run-together form is ambiguous about where one
phoneme ends and the next begins. Twi nw is a single labialised nasal; a consumer that
splits on characters reads it as n + w.
This matters most for forced alignment. With
ctc-forced-aligner, feed
space-separated units and align with --split_size word, so each phoneme unit gets one
timestamped span:
from ghana_g2p import GhanaG2P
GhanaG2P("Asante Twi").ipa("Onyankopɔn nwoma", sep=" ")
# 'o ɲ a n kʰ o pʰ ɔ n nʷ o m a' -> 13 units, 13 alignment spans
Run-together text would force --split_size char, which splits every multi-character unit.
(The aligner's normaliser folds modifier letters — kʰ→kh, nʷ→nw — but unit
boundaries survive because they are space-separated.)
Keeping punctuation
Punctuation is stripped by default. Pass punctuation=True to keep it, with each mark as
its own unit — attaching it to a neighbouring phoneme would reintroduce the boundary
ambiguity that separating units avoids:
GhanaG2P("twi").ipa("Wo ho te sɛn?", sep=" ", punctuation=True)
# 'w o h o tʰ e s ɛ n ?'
Useful when the marks carry prosody you want to model. Bracket pairs left empty once their
contents were dropped are removed, so the verse-number convention (23) does not leave a
bare ( ); brackets around real content are kept.
Two more notes:
- Apostrophes are not punctuation in several of these orthographies — in Anyin and the
Guang languages they mark glottal stop, and are phonemised as
ʔ. - Digits are dropped rather than verbalised; normalise numbers to words before phonemising if you need them spoken.
Batch use
batch() caches per word, which matters on speech corpora where transcriptions repeat:
GhanaG2P("Dagbani").batch(list_of_transcriptions)
Relationship to africa-g2p
This is a wrapper, not a fork. africa-g2p does the segmentation and holds the rule data;
ghana-g2p adds the Ghanaian registry, the donor mappings, the normalisation and patch
layers, and the provenance reporting. Fixes that belong upstream are reported there.
Licence
Apache-2.0. Underlying rule data is subject to africa-g2p's own licence.
Upstream status
The defects found while building this were reported as AfriSpeech/africa-g2p#2 and fixed upstream in #3. Because the tests assert correct output rather than the presence of a workaround, they kept passing across the change.
Now redundant (fixed upstream, kept only so older africa-g2p checkouts still work):
phonetic brackets, the Ga Greek epsilon, and the Ewe <y> mapping.
Still needed here: the Ninkare vowel-length correction, which is a per-language linguistic judgement rather than a data defect, and the missing-letter patch table.
One upstream fix improved output beyond what this wrapper could do on its own — rule keys
containing combining marks are now reachable, so Ninkare ẽ yields ɛ̃ (nasalization lowers
the vowel) instead of e plus a tilde.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ghana_g2p-0.1.1.tar.gz.
File metadata
- Download URL: ghana_g2p-0.1.1.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01017cb9f78f9d221e7552c996185d3d892701433e8f7d0a96f868d253bf082e
|
|
| MD5 |
308cd662f6c1203a8089a7924ee713bc
|
|
| BLAKE2b-256 |
f7564d31fa6a17a4d2d6e27b0e749bba0493cec224639fb98a0f65aaa987ee83
|
File details
Details for the file ghana_g2p-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ghana_g2p-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4b7b748ca9aac3736bd833ddefd63322dd47674c6f178ea704ebf370293d198
|
|
| MD5 |
aa83a6ab65e1d9c11afbf319e51c2061
|
|
| BLAKE2b-256 |
e57d846f5a45fc19e7e69dccc9f449e9af00f4d60af2c9c818e0784224621ac6
|