Skip to content

Commit 9af346a

Browse files
committed
fixing bugs in some cases when loading IBMTTS libraries.
the way of loading the libraries has been changed to minimize the possibility of errors. If the driver can't load the library, a error entry will be shown in the log. changed the way to determine the library being used. Now dll resources (ProductName) is used to determine it.
1 parent a933235 commit 9af346a

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

addon/synthDrivers/_ibmeci.py

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import threading, time
1212
import config, languageHandler, nvwave, addonHandler
1313
from logHandler import log
14+
from fileUtils import getFileVersionInfo
1415
from ._settingsDB import appConfig, speechConfig
1516

1617
addonHandler.initTranslation()
@@ -158,7 +159,7 @@ class ECILanguageDialect:
158159

159160
class EciThread(threading.Thread):
160161
def run(self):
161-
global vparams, params, speaking, endMarkersCount, isIBM
162+
global vparams, params, speaking, endMarkersCount
162163
global eciThreadId, dll, handle
163164
eciThreadId = windll.kernel32.GetCurrentThreadId()
164165
msg = wintypes.MSG()
@@ -173,11 +174,6 @@ def run(self):
173174
if v is not None:
174175
dictHandles[v[0]]=v[1]
175176
dll.eciSetDict(handle,v[1])
176-
version=eciVersion()
177-
if version>'6.2':
178-
isIBM=True
179-
else:
180-
isIBM=False
181177
started.set()
182178
while True:
183179
user32.GetMessageA(byref(msg), 0, 0, 0)
@@ -234,23 +230,20 @@ def processEciQueue():
234230
func(*args)
235231
eciQueue.task_done()
236232

237-
def eciCheck():
238-
global ttsPath, dllName, dll
233+
234+
def setPathsFromConfig():
235+
global ttsPath, dllName
239236
dllName = appConfig.dllName
240237
ttsPath = appConfig.TTSPath
241238
if not path.isabs(ttsPath):
242239
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
251240

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+")
254247
ini.seek(12)
255248
tml=ini.readline()[:-8]
256249
newPath = ttsPath + "\\"
@@ -262,10 +255,41 @@ def iniCheck():
262255
ini.truncate()
263256
ini.close()
264257

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+
265288
def eciNew():
266289
global avLangs
267290
eciCheck()
268-
eci = windll.LoadLibrary(path.join(ttsPath, dllName))
291+
updateIniPaths()
292+
eci = loadEciLibrary()
269293
b=c_int()
270294
eci.eciGetAvailableLanguages(0,byref(b))
271295
avLangs=(c_int*b.value)()
@@ -278,6 +302,7 @@ def eciNew():
278302
vparams[i] = eci.eciGetVoiceParam(handle, 0, i)
279303
return eci,handle
280304

305+
281306
@WINFUNCTYPE(c_int,c_int,c_int,c_long,c_void_p)
282307
def _callbackExec(func, *args, **kwargs):
283308
global callbackQueue

0 commit comments

Comments
 (0)