Skip to main content

PyPI - Version PyPI - Python Version PyPI - Downloads codecov

Lexphon

Lexphon is a generic, lexicon-driven phonemizer and CLI built on G2Lex. It consumes released pronunciation assets and returns normalized IPA without producing Kokoro phonemes.

g2lex-data producer -> G2Lex storage -> Lexphon runtime -> application adapter

The ownership boundary is deliberate:

  • g2lex-data obtains, transforms, validates, licenses, and publishes immutable data releases.
  • G2Lex stores and queries typed lexicon data.
  • Lexphon explicitly installs, verifies, selects, and consumes released assets.
  • KokoroG2P or another application converts generic IPA to its model-specific output.

Lexphon must never contain source acquisition or G2Lex build recipes for production dictionaries.

Package layout

There is intentionally no src/ directory. The import package lives at ./lexphon.

Install for development

python -m pip install -e ".[dev]"
pytest

Data management

Catalog access and downloads are explicit. The user-visible data states are distinct: a catalog declaration is not proof of remote publication, and remote publication is not local installation. DataStore.install() is the network-capable provisioning operation. Phonemizer, lookup, token phonemization, rendering, and local store inspection never fetch a catalog or download a lexicon.

lexphon data available lists artifacts declared by the selected catalog only. It does not download the referenced manifest or asset or verify that release files are reachable. lexphon data install retrieves and verifies those files. If a catalog points to a missing release resource, the install diagnostic reports the logical ID, manifest or asset, release tag, data version, URL, and HTTP or connectivity failure, and confirms that the failed lexicon was not installed.

lexphon data available de-DE
lexphon data install de-de:gold
lexphon data list
lexphon data info de-de:gold
lexphon data verify de-de:gold
lexphon data remove de-de:gold
lexphon phonemize --language de-DE "Die Leute kommen."

Use --catalog PATH_OR_URL and --data-home PATH for a local release or alternate store. Installation downloads the manifest first, verifies manifest and asset hashes and sizes, checks catalog and manifest identity, opens the G2Lex asset, and atomically activates a complete version. A copied, pre-populated store eliminates Lexphon catalog and lexicon downloads during runtime. Optional providers have separate provisioning requirements. The production German assets are de-de:gold, de-de:crane, de-de:espeak, and de-de:olaph. English CMUdict is available as en-us:cmudict. Membership assets can be installed for inventory use but cannot be selected as pronunciation layers.

Data release versions and the Lexphon Python package version are independent. Pin the data catalog or release during provisioning, and pin the Python dependency separately.

CLI

lexphon --help
lexphon languages
lexphon phonemize --language de-DE "Die Leute kommen."
lexphon phonemize --language de-DE --lexicon de-de:crane "Die Leute kommen."
lexphon phonemize --language de-DE --lexicon de-de:crane --tag DET "die"
lexphon phonemize --language en-US --lexicon en-us:cmudict --json "read"

JSON output has schema_version: 2 and contains the rendered IPA plus structured token fields: text, pronunciation, source category, provider, requested language, source encoding, logical lexicon ID, matched key, structured variants, selector tag, known status, punctuation status, and provenance metadata.

Inline language-control markers recognized in IPA source notation are consumed once at the Lexphon normalization boundary. They are removed from pronunciation and each variant pronunciation, while source_pronunciation and structured language_markers preserve the raw source and marker metadata for diagnostics and optional downstream routing. Optional generic provider use is explicit:

lexphon phonemize --language de-DE --fallback espeak "unbekannteswort"

Install optional providers separately when using them:

python -m pip install "lexphon[espeak]"
python -m pip install "lexphon[goruut]"

The eSpeak extra does not install the system executable; provide eSpeak or eSpeak-NG through the operating system. Goruut/Pygoruut may provision its own runtime, so a pre-populated Lexphon data store does not by itself guarantee fully offline provider startup.

Providers are disabled by default. Unknown tokens remain visible to downstream applications.

Python API

from lexphon import DataStore, Phonemizer

store = DataStore()
with Phonemizer(
    "de-DE",
    lexicons=["de-de:gold"],
    store=store,
    fallback=None,
) as g2p:
    result = g2p.phonemize_tokens("Die Leute")
    for token in result.tokens:
        print(token.text, token.pronunciation, token.source, token.lexicon_id)

phonemize_tokens() is the integration API. It preserves token-level provenance, selectors, structured variants, punctuation, and unknown words. IPA is normalized to Unicode NFC. ARPABET and CMU-style pronunciations are converted deterministically to IPA. Unsupported alphabets and invalid pronunciation tokens raise stable Lexphon exceptions.

PronunciationToken.pronunciation is derived from the first structured variant. source_pronunciation and language_markers expose its raw source notation and provenance. Downstream adapters should consume this metadata and must not search returned pronunciations for raw tags such as (en) or (de).

lookup_lexicon(token, tag=...) searches only lexicons and returns None on a miss, so it is safe for lexical evidence and language routing. lookup(token, tag=...) searches the lexicons first and then invokes the configured generic provider. Configure fallback=None, fallback="espeak", fallback="goruut", or a custom PronunciationProvider.

For example, a provider result such as (en)fˈIl(de) is returned as clean fˈIl while retaining source="provider", provider="espeak", requested_language="de-de", the raw source_pronunciation, and markers en@0 and de@4.

Batch lookup and provider contracts

lookup_many() preserves input order and checks every configured lexicon before invoking a provider. A provider receives only the missing tokens, and a runtime-checkable BatchPronunciationProvider can handle those misses in one call:

results = engine.lookup_many(["one", "two", "three"])

Batch output must contain exactly one str or None result per submitted miss. Lexphon rejects strings, bytes, non-sequences, wrong cardinality, and malformed elements with ProviderOutputError. Provider execution failures raise ProviderExecutionError; None remains a genuine direct miss. All provider output is normalized at the engine boundary.

Lexicon configuration

lexicons=None uses the language profile's default lexicons. Construction raises LexiconNotInstalledError when a required default asset is not installed. lexicons=[] explicitly selects no lexicon layers and is the provider-only configuration. Use the empty list in provider-only applications and tests when profile defaults should not be opened.

KokoroG2P boundary

KokoroG2P should import Lexphon's Python API and configure Lexphon's generic providers when needed. It converts returned IPA using its model-specific vocabulary and applies its own stress, ratings, and diagnostics policy. Lexphon does not import KokoroG2P, perform Kokoro validation, or download dictionaries during phonemization.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lexphon-0.2.0.tar.gz (43.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lexphon-0.2.0-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file lexphon-0.2.0.tar.gz.

File metadata

  • Download URL: lexphon-0.2.0.tar.gz
  • Upload date:
  • Size: 43.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for lexphon-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c2c8c4b18a9ee4ed6d2aab14564e9d0cf8b805eb4d8474ed94f58fffae962c67
MD5 384a9960bc7cac1ee85ee025af0f15c0
BLAKE2b-256 8ead8c2715b9719f77a1a883ee8d66ce32f586a565c64ba049b58e683793dce6

See more details on using hashes here.

File details

Details for the file lexphon-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: lexphon-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for lexphon-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82413da449a16f6b43e7deea32d8eedf2bd0720a3d8364779f2771b36ff7fe98
MD5 1c4b95df0a7dce575cf85f2e7949d7f3
BLAKE2b-256 68435b8f553e23e09491b9e608b23b176d4592b608b5604dadff48c29e1946e8

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.3

2 files

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 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