diff --git a/audiblez/core.py b/audiblez/core.py index 4830481..4614e13 100755 --- a/audiblez/core.py +++ b/audiblez/core.py @@ -40,10 +40,18 @@ def load_spacy(): def set_espeak_library(): """Find the espeak library path""" try: + 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':