eSpeak NG Loader
eSpeak NG Loader is a Python package (version 0.2.4, released January 16, 2025) designed to dynamically load the eSpeak NG shared library, making it available for other Python libraries or applications that require eSpeak NG functionality. It simplifies the process of interacting with the underlying C library, abstracting away platform-specific loading mechanisms. The project demonstrates an active release cadence with recent updates.
Warnings
- breaking The `espeakng-loader` package *does not install* the eSpeak NG text-to-speech engine itself. Users *must* manually install the `espeak-ng` shared library and its data files on their operating system for this Python package to function. Failure to do so will result in `RuntimeError: espeak-ng library not found`.
- gotcha The eSpeak NG library requires access to its data directory (e.g., containing `phontab` files). If `espeak-ng-data` is not found in a standard location, you might encounter errors like "Error processing file '/usr/local/share/espeak-ng-data/phontab': No such file or directory".
- gotcha When integrating `espeakng-loader` with the `phonemizer` package, use `phonemizer-fork` instead of the official `phonemizer` package due to an unresolved issue (#191).
- gotcha On Linux, audio output issues (e.g., no sound) can occur if the underlying `espeak-ng` library has problems with `pcaudiolib` or `pulseaudio`.
Install
-
pip install espeakng-loader
Imports
- get_library_path
from espeakng_loader import get_library_path
- load_library
from espeakng_loader import load_library
- make_library_available
from espeakng_loader import make_library_available
Quickstart
import os
from espeakng_loader import get_library_path, load_library, make_library_available
try:
# Get the path to the loaded eSpeak NG shared library
library_path = get_library_path()
print(f"eSpeak NG library path: {library_path}")
# Example: Directly load the library (returns a ctypes.CDLL object)
# This is useful if you're writing a direct binding or need the CDLL object.
espeak_ng_cdll = load_library()
print(f"eSpeak NG library loaded directly: {espeak_ng_cdll}")
# Example: Make the library available for other systems (e.g., via PATH on Windows/LD_LIBRARY_PATH on Linux)
# This is typically handled implicitly or by other Python bindings.
# make_library_available()
# print("eSpeak NG library made available to system.")
# Note: To actually use eSpeak NG to speak text, you would typically
# use another Python package that provides bindings to the C library,
# like 'espeakng' (pip install espeakng).
except RuntimeError as e:
print(f"Error: {e}")
print("Please ensure the eSpeak NG shared library is installed on your system.")
print("On Ubuntu/Debian: sudo apt-get install espeak-ng")
print("On Windows, download installer from https://github.com/espeak-ng/espeak-ng/releases")