Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to build cew with espeak-ng #258

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aeneas/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def check_shell_encoding(cls):
"""
is_in_utf8 = True
is_out_utf8 = True
if sys.stdin.encoding not in ["UTF-8", "UTF8"]:
if sys.stdin.encoding not in ["UTF-8", "UTF8", "utf-8", "utf8"]:
is_in_utf8 = False
if sys.stdout.encoding not in ["UTF-8", "UTF8"]:
if sys.stdout.encoding not in ["UTF-8", "UTF8", "utf-8", "utf8"]:
is_out_utf8 = False
if (is_in_utf8) and (is_out_utf8):
gf.print_success(u"shell encoding OK")
Expand Down
4 changes: 2 additions & 2 deletions aeneas/tools/abstract_cli_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ def run(self, arguments, show_help=True):
if self.use_sys:
# check that sys.stdin.encoding and sys.stdout.encoding are set to utf-8
if not gf.FROZEN:
if sys.stdin.encoding not in ["UTF-8", "UTF8"]:
if sys.stdin.encoding not in ["UTF-8", "UTF8", "utf-8", "utf8"]:
self.print_warning(u"The default input encoding is not UTF-8.")
self.print_warning(u"You might want to set 'PYTHONIOENCODING=UTF-8' in your shell.")
if sys.stdout.encoding not in ["UTF-8", "UTF8"]:
if sys.stdout.encoding not in ["UTF-8", "UTF8", "utf-8", "utf8"]:
self.print_warning(u"The default output encoding is not UTF-8.")
self.print_warning(u"You might want to set 'PYTHONIOENCODING=UTF-8' in your shell.")
# decode using sys.stdin.encoding
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
aeneas (1.7.3.1) stable; urgency=medium

* Fix spurious warnings about "encoding is not UTF-8" when encoding is "utf-8"
* Add debian packaging for python3-aeneas

-- Stephen McConnel <[email protected]> Thu, 02 Apr 2020 16:45:00 -0600

aeneas (1.7.1) stable; urgency=medium

* Fix bug #151
Expand Down
2 changes: 1 addition & 1 deletion debian/compat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7
9
20 changes: 17 additions & 3 deletions debian/control
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
Source: aeneas
Section: python
X-Python-Version: >= 2.7
Priority: optional
Maintainer: Alberto Pettarin <[email protected]>
Build-Depends: debhelper (>= 9.0.0),
dh-python,
python-all-dev,
python-setuptools,
python-numpy, python-lxml, python-bs4,
python3-all-dev,
python3-setuptools,
python3-numpy, python3-lxml, python3-bs4,
libasound2-dev, libsndfile1-dev, libespeak-dev
Standards-Version: 3.9.5
Standards-Version: 4.1.4
Homepage: https://github.com/readbeyond/aeneas

Package: python-aeneas
Architecture: any
Depends: ${misc:Depends}, ${python:Depends},
Depends: ${misc:Depends}, ${python:Depends}, ${shlibs:Depends},
espeak, espeak-data, libespeak1, vorbis-tools, ffmpeg, flac
Replaces: python3-aeneas
Description: Python library to automagically synchronize audio and text
aeneas automatically generates a synchronization map between a list of
text fragments and an audio file containing the narration of the text.
In computer science this task is known as (automatically computing a)
forced alignment.

Package: python3-aeneas
Architecture: any
Depends: ${misc:Depends}, ${python3:Depends}, ${shlibs:Depends},
espeak, espeak-data, libespeak1, vorbis-tools, ffmpeg, flac
Replaces: python-aeneas
Description: Python library to automagically synchronize audio and text
aeneas automatically generates a synchronization map between a list of
text fragments and an audio file containing the narration of the text.
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions debian/python-aeneas.lintian-overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python-aeneas: binary-without-manpage
python-aeneas: debian-changelog-file-contains-invalid-email-address
3 changes: 3 additions & 0 deletions debian/python3-aeneas.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
aeneas_check_setup.py /usr/share/python3-aeneas
VERSION /usr/share/python3-aeneas
aeneas/tools/res/audio.mp3 /usr/share/python3-aeneas/aeneas/tools/res
2 changes: 2 additions & 0 deletions debian/python3-aeneas.lintian-overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python3-aeneas: binary-without-manpage
python3-aeneas: debian-changelog-file-contains-invalid-email-address
4 changes: 3 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
export PYBUILD_NAME=aeneas

%:
dh $@ --with python2 --buildsystem=pybuild
dh $@ --with python2,python3 --buildsystem=pybuild

override_dh_shlibdeps:
dh_shlibdeps && dh_numpy && dh_numpy3
4 changes: 4 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
=========
v1.7.3.1 (2020-05-06)
---------------------
#. Fixed spurious warnings about not using UTF-8 when "utf-8" is seen
#. Added debian packaging for python3-aeneas

v1.7.4 (2018-05-??)
-------------------
Expand Down
112 changes: 96 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,25 @@ def prepare_cew_for_windows():

:rtype: bool
"""

try:
# copy espeak_sapi.dll to C:\Windows\System32\espeak.dll
espeak_dll_win_path = "C:\\Windows\\System32\\espeak.dll"
espeak_dll_dst_path = "aeneas\\cew\\espeak.dll"
espeak_dll_src_paths = [
"C:\\aeneas\\eSpeak\\espeak_sapi.dll",
"C:\\sync\\eSpeak\\espeak_sapi.dll",
"C:\\Program Files\\eSpeak\\espeak_sapi.dll",
"C:\\Program Files (x86)\\eSpeak\\espeak_sapi.dll",
]
if USE_ESPEAKNG:
espeak_dll_win_path = "C:\\Windows\\System32\\libespeak-ng.dll"
espeak_dll_dst_path = "aeneas\\cew\\libespeak-ng.dll"
espeak_dll_src_paths = [
"C:\\Program Files\\eSpeak NG\\libespeak-ng.dll",
"C:\\Program Files (x86)\\eSpeak NG\\libespeak-ng.dll",
]
else:
espeak_dll_win_path = "C:\\Windows\\System32\\espeak.dll"
espeak_dll_dst_path = "aeneas\\cew\\espeak.dll"
espeak_dll_src_paths = [
"C:\\aeneas\\eSpeak\\espeak_sapi.dll",
"C:\\sync\\eSpeak\\espeak_sapi.dll",
"C:\\Program Files\\eSpeak\\espeak_sapi.dll",
"C:\\Program Files (x86)\\eSpeak\\espeak_sapi.dll",
]
if os.path.exists(espeak_dll_dst_path):
print("[INFO] Found eSpeak DLL in %s" % espeak_dll_dst_path)
else:
Expand Down Expand Up @@ -123,13 +132,20 @@ def prepare_cew_for_windows():
# so, we copy it in the current working directory from the included thirdparty\ directory
# NOTE: PREV: copy thirdparty\espeak.lib to $PYTHON\libs\espeak.lib
# NOTE: PREV: espeak_lib_dst_path = os.path.join(sys.prefix, "libs", "espeak.lib")
espeak_lib_src_path = os.path.join(os.path.dirname(__file__), "thirdparty", "espeak.lib")
espeak_lib_dst_path = os.path.join(os.path.dirname(__file__), "espeak.lib")
if USE_ESPEAKNG:
if IS_64BITS:
espeak_lib_src_path = os.path.join(os.path.dirname(__file__), "thirdparty", "libespeak-ng-x64.lib")
else:
espeak_lib_src_path = os.path.join(os.path.dirname(__file__), "thirdparty", "libespeak-ng-x86.lib")
espeak_lib_dst_path = os.path.join(os.path.dirname(__file__), "espeak-ng.lib")
else:
espeak_lib_src_path = os.path.join(os.path.dirname(__file__), "thirdparty", "espeak.lib")
espeak_lib_dst_path = os.path.join(os.path.dirname(__file__), "espeak.lib")
if os.path.exists(espeak_lib_dst_path):
print("[INFO] Found eSpeak LIB in %s" % espeak_lib_dst_path)
else:
try:
print("[INFO] Copying eSpeak LIB into %s" % espeak_lib_dst_path)
print("[INFO] Copying eSpeak LIB from %s into %s" % (espeak_lib_src_path, espeak_lib_dst_path))
shutil.copyfile(espeak_lib_src_path, espeak_lib_dst_path)
print("[INFO] Copied eSpeak LIB")
except:
Expand All @@ -145,6 +161,55 @@ def prepare_cew_for_windows():
print("[WARN] Unexpected exception while preparing cew: %s" % e)
return False

def prepare_cew_speak_lib():
"""
Copy files needed to compile the ``cew`` Python C extension on Windows.

Return ``True`` if successful, ``False`` otherwise.

:rtype: bool
"""

try:
# NOTE: speak_lib.h is needed only while compiling the C extension, not when using it
# so, we copy it in the current working directory from the included thirdparty\ directory
if USE_ESPEAKNG:
espeak_lib_src_path = os.path.join(os.path.dirname(__file__), "thirdparty", "speak-ng_lib.h")
else:
espeak_lib_src_path = os.path.join(os.path.dirname(__file__), "thirdparty", "speak_lib.h")
espeak_lib_dst_path = os.path.join(os.path.dirname(__file__), "aeneas", "cew", "speak_lib.h")
if os.path.exists(espeak_lib_dst_path):
print("[INFO] Found eSpeak LIB in %s" % espeak_lib_dst_path)
else:
try:
print("[INFO] Copying eSpeak LIB from %s into %s" % (espeak_lib_src_path, espeak_lib_dst_path))
shutil.copyfile(espeak_lib_src_path, espeak_lib_dst_path)
print("[INFO] Copied eSpeak LIB")
except:
print("[WARN] Unable to copy the eSpeak LIB, probably because you are not running with admin privileges.")
print("[WARN] If you want to compile the C extension cew,")
print("[WARN] please copy espeak.lib from the thirdparty directory into %s" % espeak_lib_dst_path)
print("[WARN] and run the aeneas setup again.")
return False

# if here, we have completed the setup, return True
return True
except Exception as e:
print("[WARN] Unexpected exception while preparing cew: %s" % e)
return False

def get_espeak_lib():
"""
Return ``espeak-ng`` if true, ``espeak`` otherwise.

:rtype: string
"""

if USE_ESPEAKNG:
return "espeak-ng"
else:
return "espeak"


##############################################################################
#
Expand All @@ -156,6 +221,7 @@ def prepare_cew_for_windows():
IS_LINUX = (os.name == "posix") and (os.uname()[0] == "Linux")
IS_OSX = (os.name == "posix") and (os.uname()[0] == "Darwin")
IS_WINDOWS = (os.name == "nt")
IS_64BITS = (sys.maxsize > 2**32)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to patch in an import sys to get this working.


# define what values of environment variables are considered equal to True
TRUE_VALUES = [
Expand All @@ -177,6 +243,7 @@ def prepare_cew_for_windows():
WITHOUT_CEW = os.getenv("AENEAS_WITH_CEW", "True") not in TRUE_VALUES
FORCE_CEW = os.getenv("AENEAS_FORCE_CEW", "False") in TRUE_VALUES
FORCE_CFW = os.getenv("AENEAS_FORCE_CFW", "False") in TRUE_VALUES
USE_ESPEAKNG = os.getenv("AENEAS_USE_ESPEAKNG", "False") in TRUE_VALUES


##############################################################################
Expand Down Expand Up @@ -224,7 +291,7 @@ def finalize_options(self):
"aeneas/cew/cew_func.c"
],
libraries=[
"espeak"
get_espeak_lib()
]
)
EXTENSION_CFW = Extension(
Expand Down Expand Up @@ -292,8 +359,15 @@ def finalize_options(self):
print("[INFO] ")
EXTENSIONS.append(EXTENSION_CEW)
else:
print("[INFO] ********************************************************************************")
print("[INFO] Specify AENEAS_USE_ESPEAKNG=True to build aeneas with espeak-ng libraries")
print("[INFO] ********************************************************************************")
print("[INFO] ")
if IS_LINUX:
EXTENSIONS.append(EXTENSION_CEW)
if prepare_cew_speak_lib():
EXTENSIONS.append(EXTENSION_CEW)
else:
print("[WARN] Unable to complete the setup for C extension cew, not building it.")
elif IS_OSX:
print("[INFO] *********************************************************************************")
print("[INFO] Compiling the C extension cew on Mac OS X is experimental.")
Expand All @@ -307,7 +381,10 @@ def finalize_options(self):
print("[INFO] Please see the aeneas installation documentation for details.")
print("[INFO] ********************************************************************************")
print("[INFO] ")
EXTENSIONS.append(EXTENSION_CEW)
if prepare_cew_speak_lib():
EXTENSIONS.append(EXTENSION_CEW)
else:
print("[WARN] Unable to complete the setup for C extension cew, not building it.")
elif IS_WINDOWS:
print("[INFO] *****************************************************************")
print("[INFO] Compiling the C extension cew on Windows is experimental.")
Expand All @@ -317,8 +394,11 @@ def finalize_options(self):
print("[INFO] Please see the aeneas installation documentation for details.")
print("[INFO] *****************************************************************")
print("[INFO] ")
if prepare_cew_for_windows():
EXTENSIONS.append(EXTENSION_CEW)
if prepare_cew_speak_lib():
if prepare_cew_for_windows():
EXTENSIONS.append(EXTENSION_CEW)
else:
print("[WARN] Unable to complete the setup for C extension cew, not building it.")
else:
print("[WARN] Unable to complete the setup for C extension cew, not building it.")
else:
Expand Down
Binary file added thirdparty/libespeak-ng-x64.lib
Binary file not shown.
Binary file added thirdparty/libespeak-ng-x86.lib
Binary file not shown.
Loading