/
sconscript
188 lines (168 loc) · 7.06 KB
/
sconscript
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
Import([
'env',
'sourceDir',
])
import os
import ctypes
from glob import glob
class AutoFreeCDLL(ctypes.CDLL):
def __del__(self):
ctypes.windll.kernel32.FreeLibrary(self._handle)
synthDriversDir=sourceDir.Dir('synthDrivers')
espeakRepo=Dir("#include/espeak")
espeakSrcDir=espeakRepo.Dir('src')
espeakIncludeDir=espeakSrcDir.Dir('include')
sonicSrcDir=Dir("#include/sonic")
class espeak_VOICE(ctypes.Structure):
_fields_=[
('name',ctypes.c_char_p),
('languages',ctypes.c_char_p),
('identifier',ctypes.c_char_p),
('gender',ctypes.c_byte),
('age',ctypes.c_byte),
('variant',ctypes.c_byte),
('xx1',ctypes.c_byte),
('score',ctypes.c_int),
('spare',ctypes.c_void_p),
]
env=env.Clone()
#Whole-program optimization causes eSpeak to distort and worble with its Klatt4 voice
#Therefore specifically force it off
env.Append(CCFLAGS='/GL-')
# Don't analyze the code as not our project
if 'analyze' in env['nvdaHelperDebugFlags']:
env.Append(CCFLAGS='/analyze-')
# Ignore all warnings as the code is not ours
env.Replace(CCFLAGS='/W0')
env.Append(CPPPATH=['#nvdaHelper/espeak',espeakIncludeDir,espeakIncludeDir.Dir('compat'),sonicSrcDir,espeakSrcDir.Dir('ucd-tools/src/include')])
def espeak_compilePhonemeData_buildEmitter(target,source,env):
phSourceIgnores=['error_log','error_intonation','compile_prog_log','compile_report','envelopes.png']
phSources=env.Flatten([[Dir(topDir).File(f) for f in files if f not in phSourceIgnores] for topDir,subdirs,files in os.walk(source[0].abspath)])
sources=env.Flatten([phSources])
targets=[target[0].File(f) for f in ['intonations','phondata','phondata-manifest','phonindex','phontab']]
phSideEffects=[source[0].File(x) for x in phSourceIgnores]
env.SideEffect(phSideEffects,targets)
return targets,sources
def espeak_compilePhonemeData_buildAction(target,source,env):
# We want the eSpeak dll to be freed after each dictionary.
# This is because it writes to stderr but doesn't flush it.
# Unfortunately, there's no way we can flush it or use a different stream
# because our eSpeak statically links the CRT.
espeak=AutoFreeCDLL(espeakLib[0].abspath)
espeak.espeak_ng_InitializePath(os.fsencode(espeakRepo.abspath))
espeak.espeak_ng_CompileIntonation(None,None)
espeak.espeak_ng_CompilePhonemeData(22050,None,None)
espeak.espeak_Terminate()
env['BUILDERS']['espeak_compilePhonemeData']=Builder(action=env.Action(espeak_compilePhonemeData_buildAction,"Compiling phoneme data"),emitter=espeak_compilePhonemeData_buildEmitter)
def espeak_compileDict_buildAction(target,source,env):
# We want the eSpeak dll to be freed after each dictionary.
# This is because it writes to stderr but doesn't flush it.
# Unfortunately, there's no way we can flush it or use a different stream
# because our eSpeak statically links the CRT.
espeak=AutoFreeCDLL(espeakLib[0].abspath)
espeak.espeak_Initialize(0,0,os.fsencode(target[0].Dir('..').abspath),0x8000)
try:
lang=source[0].name.split('_')[0].encode()
v=espeak_VOICE(languages=lang+b'\x00')
if espeak.espeak_SetVoiceByProperties(ctypes.byref(v))!=0:
print("espeak_compileDict_action: failed to switch to language %s"%lang)
return 1
dictPath=os.fsencode(os.path.split(source[0].abspath)[0]+'/')
if espeak.espeak_ng_CompileDictionary(dictPath,None,0,None)!=0:
print("espeak_compileDict_action: failed to compile dictionary for language %s"%lang)
return
finally:
espeak.espeak_Terminate()
sonicLib=env.StaticLibrary(
target='sonic',
srcdir=sonicSrcDir.abspath,
source='sonic.c',
)
espeakLib=env.SharedLibrary(
target='espeak',
srcdir=espeakSrcDir.Dir('libespeak-ng').abspath,
source=[
# compare to src_libespeak_ng_la_SOURCES in espeak Makefile.am
"../ucd-tools/src/case.c",
"../ucd-tools/src/categories.c",
"../ucd-tools/src/ctype.c",
"../ucd-tools/src/proplist.c",
"../ucd-tools/src/scripts.c",
"../ucd-tools/src/tostring.c",
"compiledata.c",
"compiledict.c",
# "compilembrola.c", # we dont use MBROLA, this is a compile option in espeak
"dictionary.c",
"encoding.c",
"error.c",
"espeak_api.c",
"ieee80.c",
"intonation.c",
"klatt.c", # we do use KLATT, this is a compile option in espeak
# "mbrowrap.c", # we don't use MBROLA, this is a compile option in espeak
"mnemonics.c",
"numbers.c",
"phoneme.c",
"phonemelist.c",
"readclause.c",
"setlengths.c",
"spect.c",
"speech.c",
"ssml.c",
"synthdata.c",
"synthesize.c",
"synth_mbrola.c", # provides symbols used by synthesize.obj, voices.obj, and wavegen.obj
"translate.c",
"tr_languages.c",
"voices.c",
"wavegen.c",
sonicLib,
# espeak does not need to handle its own audio output so dont include:
# pcaudiolib\src\audio.c
# pcaudiolib\src\windows.c
# pcaudiolib\src\xaudio2.cpp
# These are for SAPI5, we dont need them:
# com\comentrypoints.c
# com\ttsengine.cpp
# We do not use the ASYNC compile option in espeak.
],
LIBS=['advapi32'],
)
phonemeData=env.espeak_compilePhonemeData(espeakRepo.Dir('espeak-ng-data'),espeakRepo.Dir('phsource'))
env.Depends(phonemeData,espeakLib)
for i in phonemeData:
iDir = espeakRepo.Dir('espeak-ng-data').abspath
l = len(iDir) + 1
fileName = i.abspath[l:]
env.InstallAs(os.path.join(synthDriversDir.Dir('espeak-ng-data').abspath, fileName), i)
# Move any extra dictionaries into dictsource for compilation
env.Install(espeakRepo.Dir('dictsource'),env.Glob(os.path.join(espeakRepo.abspath,'dictsource','extra','*_*')))
#Compile all dictionaries
missingDicts=['zhy', ] #'mt','tn','tt']
dictSourcePath=espeakRepo.Dir('dictsource').abspath
# Remove emoji files before compiling dictionaries.
# Currently many of these simply crash eSpeak at runtime.
# Also, our own emoji processing using CLDR data is preferred.
emojiGlob = os.path.join(espeakRepo.abspath,'dictsource','*_emoji')
for f in glob(emojiGlob):
print("Removing emoji file: %s"%f)
os.remove(f)
for f in env.Glob(os.path.join(dictSourcePath,'*_rules')):
lang=f.name.split('_')[0]
if lang in missingDicts: continue
dictFileName = lang+'_dict'
dictFile=env.Command(espeakRepo.Dir('espeak-ng-data').File(dictFileName),f,espeak_compileDict_buildAction)
dictDeps=env.Glob(os.path.join(espeakRepo.abspath,'dictsource',lang+'_*'))
dictDeps.remove(f)
env.Depends(dictFile,dictDeps)
env.Depends(dictFile,[espeakLib,phonemeData])
#Dictionaries can not be compiled in parallel, force SCons not to do this
env.SideEffect('_espeak_compileDict',dictFile)
env.InstallAs(os.path.join(synthDriversDir.Dir('espeak-ng-data').abspath, dictFileName), dictFile)
env.Install(synthDriversDir,espeakLib)
# install espeak-ng-data
targetEspeakDataDir=synthDriversDir.Dir('espeak-ng-data')
espeakDataSource=espeakRepo.Dir('espeak-ng-data')
# also install the lang and voices/!v directories. Exclude the voices/mb directory since we are not using mbrola.
env.RecursiveInstall(targetEspeakDataDir.Dir('lang'),espeakDataSource.Dir('lang').abspath)
env.RecursiveInstall(targetEspeakDataDir.Dir('voices').Dir('!v'),espeakDataSource.Dir('voices').Dir('!v').abspath)