Skip to content

Commit d6c6b1f

Browse files
authored
Merge 5a1aec0 into 9e37ced
2 parents 9e37ced + 5a1aec0 commit d6c6b1f

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

source/synthDriverHandler.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ def setSynth(name: Optional[str], isFallback: bool = False):
472472
if not isFallback:
473473
config.conf["speech"]["synth"] = name
474474
log.info(f"Loaded synthDriver {_curSynth.name}")
475+
synthChanged.notify(synth=_curSynth, audioOutputDevice=_audioOutputDevice, isFallback=isFallback)
475476
return True
476477
# As there was an error loading this synth:
477478
elif prevSynthName:
@@ -534,3 +535,16 @@ def isDebugForSynthDriver():
534535
#: Handlers are called with one keyword argument:
535536
#: synth: The L{SynthDriver} which reached the index.
536537
synthDoneSpeaking = extensionPoints.Action()
538+
539+
synthChanged = extensionPoints.Action()
540+
"""
541+
Action that allows components or add-ons to be notified of synthesizer changes.
542+
For example, when a system is controlled by a remote system and the remote system switches synth,
543+
The local system should be notified about synth parameters at the remote system.
544+
@param synth: The new synthesizer driver
545+
@type synth: L{SynthDriver}
546+
@param audioOutputDevice: The identifier of the audio output device used for this synth.
547+
@type audioOutputDevice: str
548+
@param isFallback: Whether the synth is set as fallback synth due to another synth's failure
549+
@type isFallback: bool
550+
"""

tests/unit/test_synthDriverHandler.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# A part of NonVisual Desktop Access (NVDA)
22
# This file is covered by the GNU General Public License.
33
# See the file COPYING for more details.
4-
# Copyright (C) 2021 NV Access Limited
4+
# Copyright (C) 2021-2023 NV Access Limited, Leonard de RUijter
55

66
"""Unit tests for the synthDriverHandler
77
"""
@@ -12,6 +12,7 @@
1212
from synthDrivers.oneCore import SynthDriver as OneCoreSynthDriver
1313
from typing import Callable
1414
import unittest
15+
from .extensionPointTestHelpers import actionTester
1516

1617
FAKE_DEFAULT_LANG = "fakeDefault"
1718
FAKE_DEFAULT_SYNTH_NAME = "defaultSynth"
@@ -117,3 +118,12 @@ def test_setSynth_auto_fallback_ifOneCoreDoesntSupportDefaultLanguage(self):
117118
synthDriverHandler.setSynth(None) # reset the synth so there is no fallback
118119
synthDriverHandler.setSynth("auto")
119120
self.assertEqual(synthDriverHandler.getSynth().name, "espeak")
121+
122+
def test_synthChangedExtensionPoint(self):
123+
expectedKwargs = dict(
124+
isFallback=False,
125+
audioOutputDevice = "default"
126+
)
127+
128+
with actionTester(self, synthDriverHandler.synthChanged, useAssertDictContainsSubset=True, **expectedKwargs):
129+
synthDriverHandler.setSynth("auto")

0 commit comments

Comments
 (0)