From 31b721d8b963db39bb40d68f99fdade7fece55a0 Mon Sep 17 00:00:00 2001 From: liiyee Date: Fri, 21 Feb 2025 18:12:45 +0800 Subject: [PATCH] Dynamically retrieves the Homebrew Cellar path via 'brew --cellar' and finds the first espeak-ng library. --- audiblez/core.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/audiblez/core.py b/audiblez/core.py index 5176e9d..1c6aa32 100755 --- a/audiblez/core.py +++ b/audiblez/core.py @@ -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':