Skip to main content

kitteng2p

Independent phoneme and token-ID frontend targeting the public KittenTTS v0.8 text-cleaner contract.

kitteng2p turns prepared, speakable text into eSpeak phonemes, Kitten-prepared phoneme text, character IDs, and model framing (0, *ids, 10, 0). It does not synthesize audio, load ONNX models, download voices, or perform written-to-spoken semantic normalization. Callers prepare dates, currencies, units, URLs, and abbreviations before phonemization.

The package has a flat layout and uses setuptools-scm for dynamic versioning.

Installation

Install kitteng2p and make a system eSpeak or eSpeak NG runtime available to espeakng-runtime:

python -m pip install kitteng2p

Where supported, install the optional bundled runtime assets instead:

python -m pip install "kitteng2p[bundled]"

The bundled extra provisions eSpeak runtime assets where supported. It does not install KittenTTS, a TTS model, or audio dependencies.

Quick start

from kitteng2p import KittenG2P

with KittenG2P() as g2p:
    result = g2p.phonemize_prepared("Hello, world.")

print(result.phonemes)
print(result.token_ids)
print(result.dropped_symbols)

The result's token_ids already include model framing. The convenience functions phonemes() and phoneme_ids() create and close a temporary frontend.

G2Lex sources and occurrence context

The default configuration remains eSpeak-only. To opt in to named Lexphon catalog entries or local IPA .g2lex files, configure the source stack explicitly. Local files are evaluated in the order supplied, followed by named selectors in the order supplied; source misses fall through to later sources and then eSpeak. Selected IPA values are checked against Kitten's codec and unsupported symbols fail instead of being silently dropped.

from kitteng2p import G2LexFileRef, KittenG2P, KittenG2PConfig, LinguisticToken

text = "A minute crack appeared."
minute_start = text.index("minute")
config = KittenG2PConfig(
    g2lex_files=(G2LexFileRef("./book-pronunciations.g2lex"),),
    lexicons=("lexhint",),
    lexicon_data_policy="installed-only",
)
tokens = (
    LinguisticToken(minute_start, minute_start + len("minute"), "minute", pos="NOUN", tag="NN"),
)
with KittenG2P(config) as g2p:
    result = g2p.phonemize_prepared(text, tokens=tokens)

print(result.phonemes)
print(result.pronunciation_trace)

Request-local PronunciationOverride spans have highest precedence. Tokens and override offsets are half-open character spans into the original prepared text. Context rules use the supplied tags and nearby sentence text without downloading an NLP model. PhonemizeResult.pronunciation_trace records each occurrence's source, selector, and decision reason.

Linguistic tokens are optional source-aligned annotations, not a replacement tokenizer. Kitteng2p keeps its own word segmentation authoritative: exact one-word annotations are used directly, and an annotation containing exactly one source word plus non-word material may be projected onto that word. Punctuation-only, partial-word, contraction-fragment, and other hints that cannot be mapped safely are ignored as annotations. Invalid offsets, source-text mismatches, and overlapping caller spans still fail. Explicit pronunciation overrides remain stricter and must cover complete Kitteng2p words.

discover_lexicons(language="en-us") returns catalog metadata and installed state without installing assets; only a selected named source may be provisioned under the auto policy. inspect_g2lex_file(path) reports canonical path, content and logical hashes, entry count, locale, encoding, and Kitten compatibility.

Command line

kitteng2p "Hello, world."
kitteng2p --language en-gb "Hello, world."
kitteng2p --espeak-mode cli "Hello, world."

The command prints one JSON object with the original text, prepared phonemes, framed token IDs, and any dropped symbols.

Kitten v0.8 compatibility target

kitteng2p reproduces the public KittenTTS v0.8 text-cleaner symbol inventory and model-ID framing:

  • the same pad, punctuation, ASCII-letter, and IPA symbol inventory;
  • duplicate symbols use the last dictionary index, matching upstream construction;
  • symbols outside the inventory are dropped;
  • model IDs are framed as (0, *ids, 10, 0).

This is a codec-level compatibility claim. The released KittenTTS 0.8.1 path uses phonemizer around eSpeak, while kitteng2p uses espeakng-runtime. Exact sentence-level ID parity has not been established across a representative corpus. Do not interpret codec compatibility as end-to-end phonemizer parity. See the compatibility policy.

Documentation

Dynamic versioning

Package versions are derived from Git tags through setuptools-scm. Source archives without Git metadata use the configured 0.1.dev0 fallback. Create a release tag only after the release checklist and artifact gates have passed. At runtime, kitteng2p.__version__ reports the installed distribution version.

Development

python -m pip install -e ".[dev,docs]"
python -m pytest
python -m ruff check kitteng2p tests examples
python -m mypy kitteng2p
python -m compileall -q kitteng2p tests tools examples
python docs/make.py html
python -m build --sdist --wheel

Metadata

Release files for kitteng2p 0.1.3

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

Source distribution (sdist)

Source distribution for kitteng2p 0.1.3
File Size Uploaded Provenance Actions
kitteng2p-0.1.3.tar.gz 54.7 kB Without provenance Details for kitteng2p-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 84.2 kB

Release files / kitteng2p-0.1.3.tar.gz

Download URL kitteng2p-0.1.3.tar.gz
Size 54.7 kB
Tags Source
SHA-256 checksum
How to use checksums
be6e0363d07b343947ec2538d5e6c2ac2b65082aa29234d4c5e7d6cfcea46fd2
BLAKE2b-256 checksum
How to use checksums
e6cb86d4672003f7c18e8595e2d7bf99304e5a405ae72b1fb0153d058d81432f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / kitteng2p-0.1.3-py3-none-any.whl

Download URL kitteng2p-0.1.3-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ecd7e0fd7d7c9313d56a8acdaf1092daa6d0fe9e8a13ec627c0eb7f4330da07
BLAKE2b-256 checksum
How to use checksums
bcd61bcca3bace77246a546b084939eca28092a8321a456ed750ff646c50cc6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Security for kitteng2p 0.1.3

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.

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