11
11
import threading , time
12
12
import config , languageHandler , nvwave , addonHandler
13
13
from logHandler import log
14
+ from fileUtils import getFileVersionInfo
14
15
from ._settingsDB import appConfig , speechConfig
15
16
16
17
addonHandler .initTranslation ()
@@ -158,7 +159,7 @@ class ECILanguageDialect:
158
159
159
160
class EciThread (threading .Thread ):
160
161
def run (self ):
161
- global vparams , params , speaking , endMarkersCount , isIBM
162
+ global vparams , params , speaking , endMarkersCount
162
163
global eciThreadId , dll , handle
163
164
eciThreadId = windll .kernel32 .GetCurrentThreadId ()
164
165
msg = wintypes .MSG ()
@@ -173,11 +174,6 @@ def run(self):
173
174
if v is not None :
174
175
dictHandles [v [0 ]]= v [1 ]
175
176
dll .eciSetDict (handle ,v [1 ])
176
- version = eciVersion ()
177
- if version > '6.2' :
178
- isIBM = True
179
- else :
180
- isIBM = False
181
177
started .set ()
182
178
while True :
183
179
user32 .GetMessageA (byref (msg ), 0 , 0 , 0 )
@@ -234,23 +230,20 @@ def processEciQueue():
234
230
func (* args )
235
231
eciQueue .task_done ()
236
232
237
- def eciCheck ():
238
- global ttsPath , dllName , dll
233
+
234
+ def setPathsFromConfig ():
235
+ global ttsPath , dllName
239
236
dllName = appConfig .dllName
240
237
ttsPath = appConfig .TTSPath
241
238
if not path .isabs (ttsPath ):
242
239
ttsPath = path .abspath (path .join (path .abspath (path .dirname (__file__ )), ttsPath ))
243
- if path .exists (ttsPath ) and not isIBM : iniCheck ()
244
- if not path .exists (ttsPath ): return False
245
- if dll : return True
246
- try :
247
- windll .LoadLibrary (path .join (ttsPath , dllName )).eciVersion
248
- return True
249
- except :
250
- return False
251
240
252
- def iniCheck ():
253
- ini = open (path .join (ttsPath , dllName [:- 3 ] + "ini" ), "r+" )
241
+
242
+ def updateIniPaths ():
243
+ iniPath = path .join (ttsPath , dllName [:- 3 ] + "ini" )
244
+ if path .isabs (appConfig .TTSPath ) or not path .exists (iniPath ):
245
+ return
246
+ ini = open (iniPath , "r+" )
254
247
ini .seek (12 )
255
248
tml = ini .readline ()[:- 8 ]
256
249
newPath = ttsPath + "\\ "
@@ -262,10 +255,41 @@ def iniCheck():
262
255
ini .truncate ()
263
256
ini .close ()
264
257
258
+
259
+ def loadEciLibrary ():
260
+ global isIBM
261
+ # the absolute paths must be set first.
262
+ # if the dll has been loaded, it won't load the library again.
263
+ if dll :
264
+ return dll
265
+ etidevLibPath = path .join (ttsPath , "etidev.dll" )
266
+ eciLibPath = path .join (ttsPath , dllName )
267
+ if getFileVersionInfo (eciLibPath , 'ProductName' )['ProductName' ] == 'IBMECI' :
268
+ isIBM = True
269
+ else :
270
+ isIBM = False
271
+ if path .exists (etidevLibPath ):
272
+ windll .LoadLibrary (etidevLibPath )
273
+ return windll .LoadLibrary (eciLibPath )
274
+
275
+
276
+ def eciCheck ():
277
+ if dll : return True
278
+ setPathsFromConfig ()
279
+ if not path .exists (ttsPath ): return False
280
+ try :
281
+ loadEciLibrary ().eciVersion
282
+ return True
283
+ except :
284
+ log .info ("Error checking the IBMTTS library" , exc_info = True )
285
+ return False
286
+
287
+
265
288
def eciNew ():
266
289
global avLangs
267
290
eciCheck ()
268
- eci = windll .LoadLibrary (path .join (ttsPath , dllName ))
291
+ updateIniPaths ()
292
+ eci = loadEciLibrary ()
269
293
b = c_int ()
270
294
eci .eciGetAvailableLanguages (0 ,byref (b ))
271
295
avLangs = (c_int * b .value )()
@@ -278,6 +302,7 @@ def eciNew():
278
302
vparams [i ] = eci .eciGetVoiceParam (handle , 0 , i )
279
303
return eci ,handle
280
304
305
+
281
306
@WINFUNCTYPE (c_int ,c_int ,c_int ,c_long ,c_void_p )
282
307
def _callbackExec (func , * args , ** kwargs ):
283
308
global callbackQueue
0 commit comments