Skip to main content

PyPI - Version PyPI - Python Version PyPI - Downloads codecov

espeakng-runtime

A small Python runtime adapter for eSpeak NG phonemization.

The package deliberately does not implement G2P policy for Kokoro, Piper, or any other model. It centralizes the shared eSpeak plumbing:

  • executable, shared-library, and data discovery
  • optional espeakng-loader integration
  • native ctypes execution with process-wide locking
  • CLI fallback
  • voice enumeration
  • IPA phonemization and batching
  • exact native clause/terminator output when the loaded library exposes espeak_TextToPhonemesWithTerminator
  • explicit runtime diagnostics/capabilities

Layout

This project intentionally uses a flat package layout (no src/ directory):

espeakng_runtime/
tests/
pyproject.toml

Versioning

The version is dynamic and comes from Git tags through setuptools-scm. For source archives without Git metadata, the MVP falls back to 0.1.dev0 so an unpacked zip remains installable.

git tag v0.1.0
python -m build

Install

Use a system eSpeak/eSpeak NG installation:

pip install espeakng-runtime

Or install the optional binary/data loader:

pip install "espeakng-runtime[bundled]"

Quick start

from espeakng_runtime import EspeakRuntime

with EspeakRuntime(mode="auto") as espeak:
    print(espeak.info)
    print(espeak.phonemize("Hello world", voice="en-us"))
    print(espeak.phonemize("Hello world", voice="en-us", separator="_"))
    print(espeak.clauses("Hello, world!", voice="en-us"))

mode is "auto", "native", or "cli". auto prefers a working native library and falls back to the command-line executable.

Voice arguments are caller-facing requests, not necessarily native identifiers. The runtime enumerates the active inventory and resolves language requests such as en-gb to the concrete identifier accepted by the installed eSpeak version. Resolution is cached per runtime instance, and ordinary language requests never select MBROLA voices implicitly. Use an explicit mb/... or mb-... request, or resolve_voice(..., allow_mbrola=True), when MBROLA selection is intended.

The voice argument is a public eSpeak voice/language selector. Native mode first attempts an explicit voice-name lookup and, when that fails and the native API supports it, retries the selector as a language property. This allows common locale selectors such as de-de, en-gb, and fr-fr to behave consistently with the CLI backend. RuntimeInfo.version_tuple exposes the numeric components of the reported eSpeak version, for example (1, 48, 15). Runtime cleanup is deterministic with close() or a context manager. Closing releases the Python runtime ownership; because eSpeak native state is process-global and older releases may be unsafe to terminate/reinitialize repeatedly, the initialized library remains resident for the Python process lifetime. Subsequent compatible runtimes reuse it, while conflicting library or data paths are rejected. Abandoned runtimes release their Python ownership during garbage-collection finalization. For Piper-style exact clause handling, request an exact-capable runtime:

from espeakng_runtime import EspeakRuntime

with EspeakRuntime(mode="auto", prefer_exact_clauses=True) as espeak:
    clauses = espeak.clauses("Hello, world!", voice="en-us", exact=True)

In auto mode, prefer_exact_clauses=True chooses an exact-capable native library when possible and otherwise falls back to CLI best-effort clauses. Calling clauses(..., exact=True) on a non-exact backend raises CapabilityError rather than silently degrading.

Inspect capabilities without initializing eSpeak:

from espeakng_runtime import inspect_espeak

inspection = inspect_espeak(require_exact_clauses=True)
print(inspection.native_available, inspection.cli_available)
for probe in inspection.candidates:
    print(probe.library, probe.loadable, probe.missing_symbols)

Inspection is non-initializing and does not alter process-global native state. In auto mode, a native initialization failure falls back to the CLI and is reported by RuntimeInfo.fallback_code and RuntimeInfo.fallback_reason.

Configuration

Explicit constructor arguments take precedence over environment variables:

  • ESPEAKNG_RUNTIME_EXECUTABLE
  • ESPEAKNG_RUNTIME_LIBRARY
  • ESPEAKNG_RUNTIME_DATA

The library intentionally does not read KokoroG2P/PiperG2P-specific variables; those projects can map their legacy configuration into constructor arguments during migration.

MVP scope

The package returns raw eSpeak output. Model-specific transforms stay in their consumer projects. In particular this MVP does not contain Kokoro phoneme mapping, Piper NFD/phone composition, vowel-cluster merging, lexicons, or G2P routing.

Release files for espeakng-runtime 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 espeakng-runtime 0.1.3
File Size Uploaded
espeakng_runtime-0.1.3.tar.gz 78.9 kB Details

Built distribution (wheel)

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

Total release size: 103.8 kB

Release files / espeakng_runtime-0.1.3.tar.gz

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

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

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

Release history Release notifications | RSS feed

0.1.5

2 release files

0.1.4

2 release files

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.0

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