From cfefd5863f5b4a14985e67ca9dfe0b832e433fea Mon Sep 17 00:00:00 2001 From: davidacm Date: Wed, 21 Dec 2022 03:28:35 -0600 Subject: [PATCH] updated the fix of souncard, using a little different approach. --- addon/synthDrivers/_ibmeci.py | 20 +++++++++++++++----- buildVars.py | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/addon/synthDrivers/_ibmeci.py b/addon/synthDrivers/_ibmeci.py index 4e04a7f..939bdf7 100644 --- a/addon/synthDrivers/_ibmeci.py +++ b/addon/synthDrivers/_ibmeci.py @@ -328,9 +328,7 @@ def initialize(indexCallback, doneCallback): callbackQueue = queue.Queue() callbackThread = CallbackThread() callbackThread.start() - # the next function can be called on a profile change event. That's generate a mutation in the config handlers. - # then, a delay of 1s is added, handling soundcard changes is not usual at the start of the driver. - threading.Timer(1, config.post_configProfileSwitch.register, [handleSoundcardChange]).start() + toggleProbileSwitchRegistration(config.post_configProfileSwitch.register) def speak(text): # deleted the following fix because is incompatible with NVDA's speech change command. Now send it from speak in ibmeci.py @@ -373,8 +371,7 @@ def terminate(): idleTimer.cancel() player.close() callbackQueue= callbackThread= dll= eciQueue=eciThread= handle= idleTimer= onDoneSpeaking= onIndexReached= player = None - # the situation is similar to post_configProfileSwitch.register - threading.Timer(1, config.post_configProfileSwitch.unregister, [handleSoundcardChange]).start() + toggleProbileSwitchRegistration(config.post_configProfileSwitch.unregister) def setVoice(vl): @@ -488,3 +485,16 @@ def handleSoundcardChange(): if player and currentSoundcardOutput != config.conf["speech"]["outputDevice"]: player.close() player = createPlayer(currentSampleRate) + +profileSwitchRegister = None +def toggleProbileSwitchRegistration(fn): + """ the register or unregister of the handler for config changes can't be done when a profile switch is being done. + this function helps to avoid that. + fn: the function to be called (usually register or unregister) + """ + global profileSwitchRegister + if profileSwitchRegister: + profileSwitchRegister.cancel() + profileSwitchRegister = None + profileSwitchRegister = threading.Timer(1, fn, [handleSoundcardChange]) + profileSwitchRegister.start() diff --git a/buildVars.py b/buildVars.py index cc13bac..a2b0320 100644 --- a/buildVars.py +++ b/buildVars.py @@ -19,7 +19,7 @@ # Translators: Long description to be shown for this add-on on add-on information from add-ons manager "addon_description" : _("""This is the IBMTTS synthesizer driver for NVDA."""), # version - "addon_version" : "v22.07.3", + "addon_version" : "v22.08.2-alpha", # Author(s) "addon_author" : u"David CM , x0 and others", # URL for the add-on documentation support