From 8887dc5d2a659aad6c212b39ef0e74b8c1b5f640 Mon Sep 17 00:00:00 2001 From: Mansour Kheffache Date: Tue, 28 Jan 2025 10:51:50 +0100 Subject: [PATCH 1/5] add espeak hotfix for MacOS/Windows https://github.com/bootphon/phonemizer/issues/44#issuecomment-1540885186 Detects which platform is running then applies the hotfix, assumes default installation folders. --- misaki/espeak.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/misaki/espeak.py b/misaki/espeak.py index 87c0656..ed6583a 100644 --- a/misaki/espeak.py +++ b/misaki/espeak.py @@ -1,11 +1,19 @@ import phonemizer import re +import platform FROM_ESPEAKS = sorted({'\u0303':'','a^ɪ':'I','a^ʊ':'W','d^ʒ':'ʤ','e':'A','e^ɪ':'A','r':'ɹ','t^ʃ':'ʧ','x':'k','ç':'k','ɐ':'ə','ɔ^ɪ':'Y','ə^l':'ᵊl','ɚ':'əɹ','ɬ':'l','ʔ':'t','ʔn':'tᵊn','ʔˌn\u0329':'tᵊn','ʲ':'','ʲO':'jO','ʲQ':'jQ'}.items(), key=lambda kv: -len(kv[0])) class EspeakFallback: def __init__(self, british): self.british = british + system = platform.system() + # hotfix for MacOS/Windows + # https://github.com/bootphon/phonemizer/issues/44#issuecomment-1540885186 + if system == "Darwin": + phonemizer.backend.espeak.wrapper.EspeakWrapper.set_library('/opt/homebrew/Cellar/espeak-ng/1.52.0/lib/libespeak-ng.1.dylib') + elif system == "Windows": + phonemizer.backend.espeak.wrapper.EspeakWrapper.set_library('C:\Program Files\eSpeak NG\libespeak-ng.dll') self.backend = phonemizer.backend.EspeakBackend(language=f"en-{'gb' if british else 'us'}", preserve_punctuation=True, with_stress=True, tie='^') def __call__(self, token): From 5a6939e0f7a3a5526b9b4ab4ec155a3a299da5b9 Mon Sep 17 00:00:00 2001 From: hexgrad <166769057+hexgrad@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:42:34 -0800 Subject: [PATCH 2/5] Update espeak.py --- misaki/espeak.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/misaki/espeak.py b/misaki/espeak.py index ed6583a..5d9f37f 100644 --- a/misaki/espeak.py +++ b/misaki/espeak.py @@ -1,19 +1,29 @@ import phonemizer import re -import platform + +### BEGIN ### +def set_espeak_library(): + # https://github.com/bootphon/phonemizer/issues/44#issuecomment-1540885186 + from phonemizer.backend.espeak.wrapper import EspeakWrapper + if not EspeakWrapper._ESPEAK_LIBRARY: + import os + import platform + library = dict( + Darwin='/opt/homebrew/Cellar/espeak-ng/1.52.0/lib/libespeak-ng.1.dylib', + Windows='C:\Program Files\eSpeak NG\libespeak-ng.dll', + ).get(platform.system()) + if library is not None and os.path.exists(library): + EspeakWrapper.set_library(library) + return EspeakWrapper._ESPEAK_LIBRARY + +set_espeak_library() +#### END #### FROM_ESPEAKS = sorted({'\u0303':'','a^ɪ':'I','a^ʊ':'W','d^ʒ':'ʤ','e':'A','e^ɪ':'A','r':'ɹ','t^ʃ':'ʧ','x':'k','ç':'k','ɐ':'ə','ɔ^ɪ':'Y','ə^l':'ᵊl','ɚ':'əɹ','ɬ':'l','ʔ':'t','ʔn':'tᵊn','ʔˌn\u0329':'tᵊn','ʲ':'','ʲO':'jO','ʲQ':'jQ'}.items(), key=lambda kv: -len(kv[0])) class EspeakFallback: def __init__(self, british): self.british = british - system = platform.system() - # hotfix for MacOS/Windows - # https://github.com/bootphon/phonemizer/issues/44#issuecomment-1540885186 - if system == "Darwin": - phonemizer.backend.espeak.wrapper.EspeakWrapper.set_library('/opt/homebrew/Cellar/espeak-ng/1.52.0/lib/libespeak-ng.1.dylib') - elif system == "Windows": - phonemizer.backend.espeak.wrapper.EspeakWrapper.set_library('C:\Program Files\eSpeak NG\libespeak-ng.dll') self.backend = phonemizer.backend.EspeakBackend(language=f"en-{'gb' if british else 'us'}", preserve_punctuation=True, with_stress=True, tie='^') def __call__(self, token): From 80021ad38fbc90f29c4d3f1ad4d9d10b03b088fb Mon Sep 17 00:00:00 2001 From: hexgrad <166769057+hexgrad@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:43:41 -0800 Subject: [PATCH 3/5] Update espeak.py --- misaki/espeak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misaki/espeak.py b/misaki/espeak.py index 5d9f37f..06a2846 100644 --- a/misaki/espeak.py +++ b/misaki/espeak.py @@ -12,7 +12,7 @@ def set_espeak_library(): Darwin='/opt/homebrew/Cellar/espeak-ng/1.52.0/lib/libespeak-ng.1.dylib', Windows='C:\Program Files\eSpeak NG\libespeak-ng.dll', ).get(platform.system()) - if library is not None and os.path.exists(library): + if library and os.path.exists(library): EspeakWrapper.set_library(library) return EspeakWrapper._ESPEAK_LIBRARY From f2dd5af363e4129746c21edf4fb6457f4fb87d14 Mon Sep 17 00:00:00 2001 From: hexgrad <166769057+hexgrad@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:45:10 -0800 Subject: [PATCH 4/5] Update __init__.py --- misaki/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misaki/__init__.py b/misaki/__init__.py index 3966a5f..aece342 100644 --- a/misaki/__init__.py +++ b/misaki/__init__.py @@ -1 +1 @@ -__version__ = '0.6.1' \ No newline at end of file +__version__ = '0.6.2' From b678db527db7ac121a5d26cd8abc33f25be8a98d Mon Sep 17 00:00:00 2001 From: hexgrad <166769057+hexgrad@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:45:28 -0800 Subject: [PATCH 5/5] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 1a62863..2a259fe 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='misaki', - version='0.6.1', + version='0.6.2', packages=find_packages(), package_data={ 'misaki': ['data/*.json', 'data/*.txt', 'hangul/data/*.csv', 'hangul/data/*.tsv'], @@ -30,4 +30,4 @@ 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', ], -) \ No newline at end of file +)