Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find espeak with homebrew installation #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions phonemizer/backend/espeak/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@
from phonemizer.backend.espeak.api import EspeakAPI
from phonemizer.backend.espeak.voice import EspeakVoice

def find_library_with_fallback(lib_name):
"""
Tries to find the library in common paths before falling back to ctypes.util.find_library.
"""
# Add custom search paths (e.g., Homebrew paths on macOS)
search_paths = [
"/opt/homebrew/lib",
"/usr/local/lib",
]

# Possible library file names
lib_files = [
f"lib{lib_name}.dylib", # Standard dynamic library
f"{lib_name}.dylib", # Alternate dynamic library naming
]

# Check custom paths explicitly
for path in search_paths:
for lib_file in lib_files:
full_path = os.path.join(path, lib_file)
if os.path.exists(full_path):
return full_path

# Fall back to ctypes.util.find_library
return ctypes.util.find_library(lib_name)


class EspeakWrapper:
"""Wrapper on espeak shared library
Expand Down Expand Up @@ -144,8 +170,8 @@ def library(cls):
return library.resolve()

library = (
ctypes.util.find_library('espeak-ng') or
ctypes.util.find_library('espeak'))
find_library_with_backup('espeak-ng') or
find_library_with_backup('espeak'))
if not library: # pragma: nocover
raise RuntimeError(
'failed to find espeak library')
Expand Down