Merge pull request #74 from liiyee/main

Dynamically retrieves the Homebrew Cellar path
This commit is contained in:
Claudio Santini 2025-02-21 14:36:02 +01:00 committed by GitHub
commit 28a3f85a79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -42,7 +42,14 @@ def set_espeak_library():
if os.environ.get('ESPEAK_LIBRARY'):
library = os.environ['ESPEAK_LIBRARY']
elif platform.system() == 'Darwin':
library = glob('/opt/homebrew/Cellar/espeak-ng/*/lib/*.dylib')[0]
from subprocess import check_output
try:
cellar = Path(check_output(["brew", "--cellar"], text=True).strip())
pattern = cellar / "espeak-ng" / "*" / "lib" / "*.dylib"
if not (library := next(iter(glob(str(pattern))), None)):
raise RuntimeError("No espeak-ng library found; please set the path manually")
except (subprocess.CalledProcessError, FileNotFoundError) as e:
raise RuntimeError("Cannot locate Homebrew Cellar. Is 'brew' installed and in PATH?") from e
elif platform.system() == 'Linux':
library = glob('/usr/lib/*/libespeak-ng*')[0]
elif platform.system() == 'Windows':