Get new piper module working on macOS

This commit is contained in:
Kovid Goyal 2025-07-30 07:48:13 +05:30
parent 9021419440
commit 650aeee96d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 9 additions and 5 deletions

View File

@ -22,7 +22,6 @@ from itertools import repeat
from bypy.constants import OUTPUT_DIR, PREFIX, PYTHON, python_major_minor_version from bypy.constants import OUTPUT_DIR, PREFIX, PYTHON, python_major_minor_version
from bypy.constants import SRC as CALIBRE_DIR from bypy.constants import SRC as CALIBRE_DIR
from bypy.freeze import extract_extension_modules, fix_pycryptodome, freeze_python, is_package_dir, path_to_freeze_dir from bypy.freeze import extract_extension_modules, fix_pycryptodome, freeze_python, is_package_dir, path_to_freeze_dir
from bypy.pkgs.piper import copy_piper_dir
from bypy.utils import current_dir, get_arches_in_binary, mkdtemp, py_compile, timeit, walk from bypy.utils import current_dir, get_arches_in_binary, mkdtemp, py_compile, timeit, walk
abspath, join, basename, dirname = os.path.abspath, os.path.join, os.path.basename, os.path.dirname abspath, join, basename, dirname = os.path.abspath, os.path.join, os.path.basename, os.path.dirname
@ -542,7 +541,7 @@ class Freeze:
'icudata.73', 'icui18n.73', 'icuio.73', 'icuuc.73', 'hyphen.0', 'uchardet.0', 'icudata.73', 'icui18n.73', 'icuio.73', 'icuuc.73', 'hyphen.0', 'uchardet.0',
'stemmer.0', 'xslt.1', 'exslt.0', 'xml2.2', 'z.1', 'unrar', 'lzma.5', 'stemmer.0', 'xslt.1', 'exslt.0', 'xml2.2', 'z.1', 'unrar', 'lzma.5',
'brotlicommon.1', 'brotlidec.1', 'brotlienc.1', 'zstd.1', 'jbig.2.1', 'tiff.6', 'brotlicommon.1', 'brotlidec.1', 'brotlienc.1', 'zstd.1', 'jbig.2.1', 'tiff.6',
'crypto.3', 'ssl.3', 'iconv.2', # 'ltdl.7' 'crypto.3', 'ssl.3', 'iconv.2', 'espeak-ng.1', 'onnxruntime.1.22.1', # 'ltdl.7'
): ):
x = 'lib%s.dylib' % x x = 'lib%s.dylib' % x
src = join(PREFIX, 'lib', x) src = join(PREFIX, 'lib', x)
@ -557,8 +556,8 @@ class Freeze:
dylib = join(dest, dylib) dylib = join(dest, dylib)
self.set_id(dylib, self.FID + '/' + x + '/' + os.path.basename(dylib)) self.set_id(dylib, self.FID + '/' + x + '/' + os.path.basename(dylib))
self.fix_dependencies_in_lib(dylib) self.fix_dependencies_in_lib(dylib)
# Piper TTS # espeak voices used for piper phonemization
copy_piper_dir(PREFIX, self.frameworks_dir) shutil.copytree(join(PREFIX, 'share', 'espeak-ng-data'), join(self.resources_dir, 'espeak-ng-data'))
@flush @flush
def add_site_packages(self): def add_site_packages(self):

View File

@ -200,6 +200,9 @@ elif ismacos:
openssl_lib_dirs = [os.path.join(SSL, 'lib')] openssl_lib_dirs = [os.path.join(SSL, 'lib')]
if os.path.exists(os.path.join(sw_bin_dir, 'cmake')): if os.path.exists(os.path.join(sw_bin_dir, 'cmake')):
CMAKE = os.path.join(sw_bin_dir, 'cmake') CMAKE = os.path.join(sw_bin_dir, 'cmake')
piper_inc_dirs = [sw_inc_dir, os.path.join(sw_inc_dir, 'onnxruntime')]
piper_lib_dirs = [sw_lib_dir]
piper_libs = ['espeak-ng', 'onnxruntime']
else: else:
freetype_inc_dirs = pkgconfig_include_dirs('freetype2', 'FT_INC_DIR', freetype_inc_dirs = pkgconfig_include_dirs('freetype2', 'FT_INC_DIR',
'/usr/include/freetype2') '/usr/include/freetype2')

View File

@ -12,7 +12,7 @@ from threading import Lock, Thread
from typing import Any, NamedTuple from typing import Any, NamedTuple
import calibre_extensions.piper as piper import calibre_extensions.piper as piper
from calibre.constants import iswindows from calibre.constants import ismacos, iswindows
DEFAULT_LENGTH_SCALE = 1.0 DEFAULT_LENGTH_SCALE = 1.0
DEFAULT_NOISE_SCALE = 0.667 DEFAULT_NOISE_SCALE = 0.667
@ -64,6 +64,8 @@ def espeak_data_dir() -> str:
return '' return ''
if iswindows: if iswindows:
return os.path.join(os.path.dirname(sys.executables_location), 'share', 'espeak-ng-data') return os.path.join(os.path.dirname(sys.executables_location), 'share', 'espeak-ng-data')
if ismacos:
return os.path.join(os.path.dirname(sys.frameworks_dir), 'Resources', 'espeak-ng-data')
return os.path.join(sys.executables_location, 'share', 'espeak-ng-data') return os.path.join(sys.executables_location, 'share', 'espeak-ng-data')