Skip to content

Commit 28a3f85

Browse files
authored
Merge pull request #74 from liiyee/main
Dynamically retrieves the Homebrew Cellar path
2 parents 97b46b4 + 31b721d commit 28a3f85

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

audiblez/core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ def set_espeak_library():
4242
if os.environ.get('ESPEAK_LIBRARY'):
4343
library = os.environ['ESPEAK_LIBRARY']
4444
elif platform.system() == 'Darwin':
45-
library = glob('/opt/homebrew/Cellar/espeak-ng/*/lib/*.dylib')[0]
45+
from subprocess import check_output
46+
try:
47+
cellar = Path(check_output(["brew", "--cellar"], text=True).strip())
48+
pattern = cellar / "espeak-ng" / "*" / "lib" / "*.dylib"
49+
if not (library := next(iter(glob(str(pattern))), None)):
50+
raise RuntimeError("No espeak-ng library found; please set the path manually")
51+
except (subprocess.CalledProcessError, FileNotFoundError) as e:
52+
raise RuntimeError("Cannot locate Homebrew Cellar. Is 'brew' installed and in PATH?") from e
4653
elif platform.system() == 'Linux':
4754
library = glob('/usr/lib/*/libespeak-ng*')[0]
4855
elif platform.system() == 'Windows':

0 commit comments

Comments
 (0)