Skip to content

Commit

Permalink
fixing bugs in some cases when loading IBMTTS libraries.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidacm committed Feb 1, 2023
1 parent a933235 commit 9af346a
Showing 1 changed file with 44 additions and 19 deletions.
63 changes: 44 additions & 19 deletions addon/synthDrivers/_ibmeci.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import threading, time
import config, languageHandler, nvwave, addonHandler
from logHandler import log
from fileUtils import getFileVersionInfo
from ._settingsDB import appConfig, speechConfig

addonHandler.initTranslation()
Expand Down Expand Up @@ -158,7 +159,7 @@ class ECILanguageDialect:

class EciThread(threading.Thread):
def run(self):
global vparams, params, speaking, endMarkersCount, isIBM
global vparams, params, speaking, endMarkersCount
global eciThreadId, dll, handle
eciThreadId = windll.kernel32.GetCurrentThreadId()
msg = wintypes.MSG()
Expand All @@ -173,11 +174,6 @@ def run(self):
if v is not None:
dictHandles[v[0]]=v[1]
dll.eciSetDict(handle,v[1])
version=eciVersion()
if version>'6.2':
isIBM=True
else:
isIBM=False
started.set()
while True:
user32.GetMessageA(byref(msg), 0, 0, 0)
Expand Down Expand Up @@ -234,23 +230,20 @@ def processEciQueue():
func(*args)
eciQueue.task_done()

def eciCheck():
global ttsPath, dllName, dll

def setPathsFromConfig():
global ttsPath, dllName
dllName = appConfig.dllName
ttsPath = appConfig.TTSPath
if not path.isabs(ttsPath):
ttsPath = path.abspath(path.join(path.abspath(path.dirname(__file__)), ttsPath))
if path.exists(ttsPath) and not isIBM: iniCheck()
if not path.exists(ttsPath): return False
if dll: return True
try:
windll.LoadLibrary(path.join(ttsPath, dllName)).eciVersion
return True
except:
return False

def iniCheck():
ini=open(path.join(ttsPath, dllName[:-3] +"ini"), "r+")

def updateIniPaths():
iniPath = path.join(ttsPath, dllName[:-3] +"ini")
if path.isabs(appConfig.TTSPath) or not path.exists(iniPath):
return
ini=open(iniPath, "r+")
ini.seek(12)
tml=ini.readline()[:-8]
newPath = ttsPath + "\\"
Expand All @@ -262,10 +255,41 @@ def iniCheck():
ini.truncate()
ini.close()


def loadEciLibrary():
global isIBM
# the absolute paths must be set first.
# if the dll has been loaded, it won't load the library again.
if dll:
return dll
etidevLibPath = path.join(ttsPath, "etidev.dll")
eciLibPath = path.join(ttsPath, dllName)
if getFileVersionInfo(eciLibPath, 'ProductName')['ProductName'] == 'IBMECI':
isIBM = True
else:
isIBM = False
if path.exists(etidevLibPath):
windll.LoadLibrary(etidevLibPath)
return windll.LoadLibrary(eciLibPath)


def eciCheck():
if dll: return True
setPathsFromConfig()
if not path.exists(ttsPath): return False
try:
loadEciLibrary().eciVersion
return True
except:
log.info("Error checking the IBMTTS library", exc_info=True)
return False


def eciNew():
global avLangs
eciCheck()
eci = windll.LoadLibrary(path.join(ttsPath, dllName))
updateIniPaths()
eci = loadEciLibrary()
b=c_int()
eci.eciGetAvailableLanguages(0,byref(b))
avLangs=(c_int*b.value)()
Expand All @@ -278,6 +302,7 @@ def eciNew():
vparams[i] = eci.eciGetVoiceParam(handle, 0, i)
return eci,handle


@WINFUNCTYPE(c_int,c_int,c_int,c_long,c_void_p)
def _callbackExec(func, *args, **kwargs):
global callbackQueue
Expand Down

0 comments on commit 9af346a

Please sign in to comment.