Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add synthDriverHandler.synthChanged extension point #14618

Merged
merged 7 commits into from Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/synthDriverHandler.py
Expand Up @@ -472,6 +472,7 @@ def setSynth(name: Optional[str], isFallback: bool = False):
if not isFallback:
config.conf["speech"]["synth"] = name
log.info(f"Loaded synthDriver {_curSynth.name}")
synthChanged.notify(synth=_curSynth, audioOutputDevice=_audioOutputDevice, isFallback=isFallback)
return True
# As there was an error loading this synth:
elif prevSynthName:
Expand Down Expand Up @@ -534,3 +535,16 @@ def isDebugForSynthDriver():
#: Handlers are called with one keyword argument:
#: synth: The L{SynthDriver} which reached the index.
synthDoneSpeaking = extensionPoints.Action()

synthChanged = extensionPoints.Action()
"""
Action that allows components or add-ons to be notified of synthesizer changes.
For example, when a system is controlled by a remote system and the remote system switches synth,
The local system should be notified about synth parameters at the remote system.
@param synth: The new synthesizer driver
@type synth: L{SynthDriver}
@param audioOutputDevice: The identifier of the audio output device used for this synth.
@type audioOutputDevice: str
@param isFallback: Whether the synth is set as fallback synth due to another synth's failure
@type isFallback: bool
"""
17 changes: 16 additions & 1 deletion tests/unit/test_synthDriverHandler.py
@@ -1,7 +1,7 @@
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
# Copyright (C) 2021 NV Access Limited
# Copyright (C) 2021-2023 NV Access Limited, Leonard de RUijter

"""Unit tests for the synthDriverHandler
"""
Expand All @@ -12,6 +12,7 @@
from synthDrivers.oneCore import SynthDriver as OneCoreSynthDriver
from typing import Callable
import unittest
from .extensionPointTestHelpers import actionTester

FAKE_DEFAULT_LANG = "fakeDefault"
FAKE_DEFAULT_SYNTH_NAME = "defaultSynth"
Expand Down Expand Up @@ -117,3 +118,17 @@ def test_setSynth_auto_fallback_ifOneCoreDoesntSupportDefaultLanguage(self):
synthDriverHandler.setSynth(None) # reset the synth so there is no fallback
synthDriverHandler.setSynth("auto")
self.assertEqual(synthDriverHandler.getSynth().name, "espeak")

def test_synthChangedExtensionPoint(self):
expectedKwargs = dict(
isFallback=False,
audioOutputDevice="default"
)

with actionTester(
self,
synthDriverHandler.synthChanged,
useAssertDictContainsSubset=True,
**expectedKwargs
):
synthDriverHandler.setSynth("auto")