Skip to content

Commit fb7a72b

Browse files
committed
Change output device script: Bugfix: The script can now be used with the 'Silence' synth being active.
1 parent 2c360c1 commit fb7a72b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

globalPlugins/changeOutputDevice.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import nvwave
1313
from scriptHandler import script
1414
import addonHandler
15+
import tones
16+
from synthDriverHandler import getSynth, setSynth
17+
import core
1518

1619
# Store original NVDA translation function.
1720
nvdaTranslations = _
@@ -39,14 +42,16 @@ def script_cycleAudioOutputDevices(self, gesture):
3942
selection = (selection + 1) % len(deviceNames)
4043
audioDevice = deviceNames[selection]
4144
config.conf["speech"]["outputDevice"] = audioDevice
42-
# Reinitialize the tones and speech modules to update the audio device
45+
46+
# Reinitialize the tones module and the synth to update the audio device
4347
# On the contrary to what is written in onOK method of SynthesizerSelectionDialog,
4448
# reinitializing only tones module is not enough.
45-
import tones
46-
import speech
47-
speech.terminate()
48-
tones.terminate()
49-
tones.initialize()
50-
speech.initialize()
51-
ui.message(audioDevice)
49+
# Note: we need to reinitialize synth out of a script to avoid an error if the current synth is silence.
50+
def runOutOfScript():
51+
tones.terminate()
52+
setSynth(getSynth().name)
53+
tones.initialize()
54+
ui.message(audioDevice)
55+
core.callLater(0, runOutOfScript)
56+
return
5257

0 commit comments

Comments
 (0)