forked from readbeyond/aeneas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
606 lines (555 loc) · 19 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
#!/usr/bin/env python
# coding=utf-8
# aeneas is a Python/C library and a set of tools
# to automagically synchronize audio and text (aka forced alignment)
#
# Copyright (C) 2012-2013, Alberto Pettarin (www.albertopettarin.it)
# Copyright (C) 2013-2015, ReadBeyond Srl (www.readbeyond.it)
# Copyright (C) 2015-2017, Alberto Pettarin (www.albertopettarin.it)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Set the aeneas package up.
"""
from setuptools import Extension
from setuptools import setup
import io
import os
import shutil
import sys
import io
__author__ = "Alberto Pettarin"
__email__ = "aeneas@readbeyond.it"
__copyright__ = """
Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it)
Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it)
Copyright 2015-2017, Alberto Pettarin (www.albertopettarin.it)
"""
__license__ = "GNU AGPL 3"
__status__ = "Production"
__version__ = "1.7.3"
##############################################################################
#
# you might need to edit the information below this line
#
##############################################################################
# package version
# NOTE: generate a new one for each PyPI upload, otherwise it will fail
PKG_VERSION = "1.7.3.0"
# required packages to install
# NOTE: always use exact version numbers
# NOTE: this list should be the same as requirements.txt
PKG_INSTALL_REQUIRES = [
"BeautifulSoup4>=4.5.1",
"lxml>=3.6.0",
"numpy>=1.9"
]
# required packages to install extra tools
PKG_EXTRAS_REQUIRE = {
"full": [
"boto3>=1.4.2",
"Pillow>=3.1.1",
"requests>=2.9.1",
"tgt>=1.4.2",
"youtube-dl>=2016.9.27",
],
"nopillow": [
"boto3>=1.4.2",
"requests>=2.9.1",
"tgt>=1.4.2",
"youtube-dl>=2016.9.27",
],
"boto3": [
"boto3>=1.4.2",
],
"pillow": [
"Pillow>=3.1.1",
],
"requests": [
"requests>=2.9.1",
],
"tgt": [
"tgt>=1.4.2",
]
}
# packages to be distributed
# NOTE: not including the aeneas.test package to keep the size small
PKG_PACKAGES = [
"aeneas",
"aeneas.cdtw",
"aeneas.cew",
"aeneas.cfw",
"aeneas.cmfcc",
"aeneas.cwave",
"aeneas.extra",
"aeneas.syncmap",
"aeneas.tools",
"aeneas.ttswrappers"
]
# data files to be distributed
# NOTE: .py files will be added automatically
PKG_PACKAGE_DATA = {
"aeneas": [
"res/*",
"*.md"
],
"aeneas.cdtw": [
"*.c",
"*.h",
"*.md"
],
"aeneas.cew": [
"*.c",
"*.h",
"*.md",
"*.dll"
],
"aeneas.cew": [
"*.cc",
"*.h",
"*.md"
],
"aeneas.cmfcc": [
"*.c",
"*.h",
"*.md"
],
"aeneas.cwave": [
"*.c",
"*.h",
"*.md"
],
"aeneas.extra": [
"*.md"
],
"aeneas.syncmap": [
"*.md"
],
"aeneas.tools": [
"res/*",
"*.md"
],
"aeneas.ttswrappers": [
"*.md"
]
}
# scripts to be installed globally
# on Linux and Mac OS X, use the file without extension
# on Windows, use the file with .py extension
PKG_SCRIPTS = [
"bin/aeneas_check_setup",
"bin/aeneas_convert_syncmap",
"bin/aeneas_download",
"bin/aeneas_execute_job",
"bin/aeneas_execute_task",
"bin/aeneas_plot_waveform",
"bin/aeneas_synthesize_text",
"bin/aeneas_validate",
]
##############################################################################
#
# do not edit the metadata below this line
#
##############################################################################
# package name
PKG_NAME = "aeneas"
# package author
PKG_AUTHOR = "Alberto Pettarin"
# package author email
PKG_AUTHOR_EMAIL = "alberto@albertopettarin.it"
# package URL
PKG_URL = "https://github.com/readbeyond/aeneas"
# package license
PKG_LICENSE = "GNU Affero General Public License v3 (AGPL v3)"
# human-readable descriptions
PKG_SHORT_DESCRIPTION = "aeneas is a Python/C library and a set of tools to automagically synchronize audio and text (aka forced alignment)"
try:
PKG_LONG_DESCRIPTION = io.open("README.rst", "r", encoding="utf-8").read()
except:
PKG_LONG_DESCRIPTION = PKG_SHORT_DESCRIPTION
# PyPI keywords
PKG_KEYWORDS = [
"AUD",
"AWS Polly TTS API",
"CSV",
"DTW",
"EAF",
"ELAN",
"EPUB 3 Media Overlay",
"EPUB 3",
"EPUB",
"Festival",
"JSON",
"MFCC",
"Mel-frequency cepstral coefficients",
"Nuance TTS API",
"ReadBeyond Sync",
"ReadBeyond",
"SBV",
"SMIL",
"SRT",
"SSV",
"SUB",
"TGT",
"TSV",
"TTML",
"TTS",
"TextGrid",
"VTT",
"XML",
"aeneas",
"audio/text alignment",
"dynamic time warping",
"eSpeak",
"eSpeak-ng",
"espeak",
"espeak-ng",
"festival",
"ffmpeg",
"ffprobe",
"forced alignment",
"media overlay",
"rb_smil_emulator",
"speech to text",
"subtitles",
"sync",
"synchronization",
"text to speech",
"text2wave",
"tts",
]
# PyPI classifiers
PKG_CLASSIFIERS = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Natural Language :: English",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: C",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Topic :: Education",
"Topic :: Multimedia",
"Topic :: Multimedia :: Sound/Audio",
"Topic :: Multimedia :: Sound/Audio :: Analysis",
"Topic :: Multimedia :: Sound/Audio :: Speech",
"Topic :: Printing",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing",
"Topic :: Text Processing :: Linguistic",
"Topic :: Text Processing :: Markup",
"Topic :: Text Processing :: Markup :: HTML",
"Topic :: Text Processing :: Markup :: XML",
"Topic :: Utilities"
]
__author__ = "Alberto Pettarin"
__email__ = "aeneas@readbeyond.it"
__copyright__ = """
Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it)
Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it)
Copyright 2015-2017, Alberto Pettarin (www.albertopettarin.it)
"""
__license__ = "GNU AGPL 3"
__status__ = "Production"
__version__ = "1.7.3"
##############################################################################
#
# Windows-specific setup for compiling cew
#
##############################################################################
def prepare_cew_for_windows():
"""
Copy files needed to compile the ``cew`` Python C extension on Windows.
A glorious day, when Microsoft will offer a decent support
for Python and shared libraries,
all this mess will be unnecessary and it should be removed.
May that day come soon.
Return ``True`` if successful, ``False`` otherwise.
: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 os.path.exists(espeak_dll_dst_path):
print("[INFO] Found eSpeak DLL in %s" % espeak_dll_dst_path)
else:
found = False
copied = False
for src_path in espeak_dll_src_paths:
if os.path.exists(src_path):
found = True
print("[INFO] Copying eSpeak DLL from %s into %s" % (src_path, espeak_dll_dst_path))
try:
shutil.copyfile(src_path, espeak_dll_dst_path)
copied = True
print("[INFO] Copied eSpeak DLL")
except:
pass
break
if not found:
print("[WARN] Unable to find the eSpeak DLL, probably because you installed eSpeak in a non-standard location.")
print("[WARN] If you want to run aeneas with the C extension cew,")
print("[WARN] please copy espeak_sapi.dll from your eSpeak directory to %s" % espeak_dll_win_path)
# print("[WARN] and run the aeneas setup again.")
# return False
elif not copied:
print("[WARN] Unable to copy the eSpeak DLL, probably because you are not running with admin privileges.")
print("[WARN] If you want to run aeneas with the C extension cew,")
print("[WARN] please copy espeak_sapi.dll from your eSpeak directory to %s" % espeak_dll_win_path)
# print("[WARN] and run the aeneas setup again.")
# return False
# NOTE: espeak.lib 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
# 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 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)
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
##############################################################################
#
# find the OS out and read environment variables for options
#
##############################################################################
# get platform
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_OSX_ARM = IS_OSX and (os.uname().machine == "arm64")
# define what values of environment variables are considered equal to True
TRUE_VALUES = [
"TRUE",
"True",
"true",
"YES",
"Yes",
"yes",
"1",
1
]
# check whether the user set additional parameters using environment variables
# NOTE by the book this should be done by subclassing the setuptools Distribution object
# but for now using environment variables is good enough
WITHOUT_CDTW = os.getenv("AENEAS_WITH_CDTW", "True") not in TRUE_VALUES
WITHOUT_CMFCC = os.getenv("AENEAS_WITH_CMFCC", "True") not in TRUE_VALUES
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
##############################################################################
#
# actual setup
#
##############################################################################
# try importing numpy: if it fails, warn user and exit
try:
from numpy import get_include
from numpy.distutils import misc_util
except ImportError:
print("[ERRO] You must install numpy before installing aeneas")
print("[INFO] Try the following command:")
print("[INFO] $ sudo pip install numpy")
sys.exit(1)
# to compile cdtw and cmfcc, we need to include the NumPy dirs
INCLUDE_DIRS = [misc_util.get_numpy_include_dirs()]
# scripts to be installed globally
# on Linux and Mac OS X, use the file without extension
# on Windows, use the file with .py extension
if IS_WINDOWS:
PKG_SCRIPTS = [s + ".py" for s in PKG_SCRIPTS]
# prepare Extension objects
EXTENSION_CDTW = Extension(
name="aeneas.cdtw.cdtw",
sources=[
"aeneas/cdtw/cdtw_py.c",
"aeneas/cdtw/cdtw_func.c",
"aeneas/cint/cint.c"
],
include_dirs=[
get_include()
]
)
EXTENSION_CMFCC = Extension(
name="aeneas.cmfcc.cmfcc",
sources=[
"aeneas/cmfcc/cmfcc_py.c",
"aeneas/cmfcc/cmfcc_func.c",
"aeneas/cwave/cwave_func.c",
"aeneas/cint/cint.c"
],
include_dirs=[
get_include()
]
)
cew_library_dirs = None
if IS_OSX_ARM: # On Apple Silicon we need to add the /opt/homebrew/lib so that the brew-installed espeak is found
cew_library_dirs = ["/opt/homebrew/lib"]
EXTENSION_CEW = Extension(
name="aeneas.cew.cew",
sources=[
"aeneas/cew/cew_py.c",
"aeneas/cew/cew_func.c"
],
library_dirs=cew_library_dirs,
libraries=[
"espeak"
]
)
EXTENSION_CFW = Extension(
name="aeneas.cfw.cfw",
sources=[
"aeneas/cfw/cfw_py.cc",
"aeneas/cfw/cfw_func.cc"
],
include_dirs=[
"aeneas/cfw/festival",
"aeneas/cfw/speech_tools"
],
libraries=[
"Festival",
"estools",
"estbase",
"eststring",
]
)
# cwave is ready, but currently not used
# EXTENSION_CWAVE = Extension(
# name="aeneas.cwave.cwave",
# sources=[
# "aeneas/cwave/cwave_py.c",
# "aeneas/cwave/cwave_func.c"
# ],
# include_dirs=[
# get_include()
# ]
# )
# append or ignore cew extension as requested
EXTENSIONS = []
if WITHOUT_CDTW:
print("[INFO] ************************************************************")
print("[INFO] The user specified AENEAS_WITH_CDTW=False: not building cdtw")
print("[INFO] ************************************************************")
print("[INFO] ")
else:
EXTENSIONS.append(EXTENSION_CDTW)
if WITHOUT_CMFCC:
print("[INFO] **************************************************************")
print("[INFO] The user specified AENEAS_WITH_CMFCC=False: not building cmfcc")
print("[INFO] **************************************************************")
print("[INFO] ")
else:
EXTENSIONS.append(EXTENSION_CMFCC)
if WITHOUT_CEW:
print("[INFO] **********************************************************")
print("[INFO] The user specified AENEAS_WITH_CEW=False: not building cew")
print("[INFO] **********************************************************")
print("[INFO] ")
elif FORCE_CEW:
print("[INFO] ********************************************************************************")
print("[INFO] The user specified AENEAS_FORCE_CEW=True: attempting to build cew without checks")
print("[INFO] ********************************************************************************")
print("[INFO] ")
EXTENSIONS.append(EXTENSION_CEW)
else:
if IS_LINUX:
EXTENSIONS.append(EXTENSION_CEW)
elif IS_OSX:
print("[INFO] *********************************************************************************")
print("[INFO] Compiling the C extension cew on Mac OS X is experimental.")
print("[INFO] ")
print("[INFO] Before installing aeneas with cew, you must run:")
print("[INFO] $ brew update && brew upgrade --cleanup espeak")
print("[INFO] to run the new brew formula installing libespeak, the library version of espeak.")
print("[INFO] ")
print("[INFO] If you experience problems, disable cew compilation by specifying")
print("[INFO] the environment variable AENEAS_WITH_CEW=False .")
print("[INFO] Please see the aeneas installation documentation for details.")
print("[INFO] ********************************************************************************")
print("[INFO] ")
EXTENSIONS.append(EXTENSION_CEW)
elif IS_WINDOWS:
print("[INFO] *****************************************************************")
print("[INFO] Compiling the C extension cew on Windows is experimental.")
print("[INFO] ")
print("[INFO] If you experience problems, disable cew compilation by specifying")
print("[INFO] the environment variable AENEAS_WITH_CEW=False .")
print("[INFO] Please see the aeneas installation documentation for details.")
print("[INFO] *****************************************************************")
print("[INFO] ")
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("[INFO] The C extension cew is not available for your OS.")
if FORCE_CFW:
print("[INFO] ********************************************************************************")
print("[INFO] The user specified AENEAS_FORCE_CFW=True: attempting to build cfw without checks")
print("[INFO] ********************************************************************************")
print("[INFO] ")
EXTENSIONS.append(EXTENSION_CFW)
# now we are ready to call setup()
setup(
name=PKG_NAME,
version=PKG_VERSION,
packages=PKG_PACKAGES,
package_data=PKG_PACKAGE_DATA,
description=PKG_SHORT_DESCRIPTION,
long_description=PKG_LONG_DESCRIPTION,
author=PKG_AUTHOR,
author_email=PKG_AUTHOR_EMAIL,
url=PKG_URL,
license=PKG_LICENSE,
keywords=PKG_KEYWORDS,
classifiers=PKG_CLASSIFIERS,
install_requires=PKG_INSTALL_REQUIRES,
extras_require=PKG_EXTRAS_REQUIRE,
scripts=PKG_SCRIPTS,
include_dirs=INCLUDE_DIRS,
ext_modules=EXTENSIONS
)