Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bcdf4c0
SPeech: Enable unicode normalization by default
LeonarddeR May 27, 2024
82e2bd7
Add input gestures
LeonarddeR May 27, 2024
b7844cb
Speak normalized on character nav
LeonarddeR May 27, 2024
9d6d799
Fix unit test
LeonarddeR May 28, 2024
7d09e8d
Lint
LeonarddeR May 28, 2024
b4d74d3
Merge remote-tracking branch 'origin/master' into normalizationFollowUp
LeonarddeR May 29, 2024
438d217
Merge remote-tracking branch 'origin/master' into normalizationFollowUp
LeonarddeR May 31, 2024
50f6087
Update user guide and change default
LeonarddeR May 31, 2024
f94c55f
Fix announcing ligatures
LeonarddeR May 31, 2024
b35ebde
Updates to speech
LeonarddeR May 31, 2024
19f698a
Fix suppression
LeonarddeR May 31, 2024
13c2168
Last fixups, opefully
LeonarddeR Jun 1, 2024
5f54f77
Use walrus
LeonarddeR Jun 1, 2024
b56c369
Slightly expand mixed test
LeonarddeR Jun 1, 2024
e9faa2b
Add a SequenceMatcher monkey patch
LeonarddeR Jun 1, 2024
b854b76
Better assertions
LeonarddeR May 29, 2024
3353244
move the context manager
LeonarddeR Jun 1, 2024
add5113
Lint
LeonarddeR Jun 1, 2024
7224910
Unit tests
LeonarddeR Jun 3, 2024
9a2a051
Change test that currently fails and needs fix
LeonarddeR Jun 4, 2024
5e6149e
Repalce non breaking spaces
LeonarddeR Jun 4, 2024
2087328
ANother failing test
LeonarddeR Jun 6, 2024
5c30820
New implementation based on uniscribe
LeonarddeR Jun 6, 2024
244ca64
Merge remote-tracking branch 'origin/master' into normalizationFollowUp
LeonarddeR Jun 6, 2024
1ae779a
Even more compact code
LeonarddeR Jun 6, 2024
d25042b
Get rid of duplicated code
LeonarddeR Jun 6, 2024
6d801d1
Apply suggestions from code review
seanbudd Jun 7, 2024
afd2aec
Add processText doc string
LeonarddeR Jun 8, 2024
50e35bf
Add _getSpellingSpeechWithoutCharMode docstring
LeonarddeR Jun 8, 2024
7c3fd6f
Add return type
LeonarddeR Jun 8, 2024
5bf722f
Import Generator
LeonarddeR Jun 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/config/configSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
symbolLevel = integer(default=100)
trustVoiceLanguage = boolean(default=true)
unicodeNormalization = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="disabled")
reportNormalizedForCharacterNavigation = boolean(default=true)
includeCLDR = boolean(default=True)
beepSpeechModePitch = integer(default=10000,min=50,max=11025)
outputDevice = string(default=default)
Expand Down
56 changes: 56 additions & 0 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,34 @@ def script_braille_cycleShowSelection(self, gesture: inputCore.InputGesture) ->
braille.handler.initialDisplay()
ui.message(msg)

@script(
# Translators: Input help mode message for Braille Unicode normalization command.
description=_("Cycle through the braille Unicode normalization states"),
category=SCRCAT_BRAILLE
)
def script_braille_cycleUnicodeNormalization(self, gesture: inputCore.InputGesture) -> None:
featureFlag: FeatureFlag = config.conf["braille"]["unicodeNormalization"]
boolFlag: BoolFlag = featureFlag.enumClassType
values = [x.value for x in boolFlag]
currentValue = featureFlag.value.value
nextValueIndex = (currentValue % len(values)) + 1
nextName: str = boolFlag(nextValueIndex).name
config.conf["braille"]["unicodeNormalization"] = nextName
featureFlag = config.conf["braille"]["unicodeNormalization"]
if featureFlag.isDefault():
# Translators: Used when reporting braille Unicode normalization state
# (default behavior).
msg = _("Braille Unicode normalization default ({default})").format(
default=featureFlag.behaviorOfDefault.displayString
)
else:
# Translators: Used when reporting braille Unicode normalization state
# (disabled or enabled).
msg = _("Braille Unicode normalization {state}").format(
state=BoolFlag[nextName].displayString
)
ui.message(msg)

@script(
description=_(
# Translators: Input help mode message for report clipboard text command.
Expand Down Expand Up @@ -4343,6 +4371,34 @@ def script_toggleReportCLDR(self, gesture):
characterProcessing.clearSpeechSymbols()
ui.message(state)

@script(
# Translators: Input help mode message for speech Unicode normalization command.
description=_("Cycle through the speech Unicode normalization states"),
category=SCRCAT_SPEECH
)
def script_speech_cycleUnicodeNormalization(self, gesture: inputCore.InputGesture) -> None:
featureFlag: FeatureFlag = config.conf["speech"]["unicodeNormalization"]
boolFlag: BoolFlag = featureFlag.enumClassType
values = [x.value for x in boolFlag]
currentValue = featureFlag.value.value
nextValueIndex = (currentValue % len(values)) + 1
nextName: str = boolFlag(nextValueIndex).name
config.conf["speech"]["unicodeNormalization"] = nextName
featureFlag = config.conf["speech"]["unicodeNormalization"]
if featureFlag.isDefault():
# Translators: Used when reporting speech Unicode normalization state
# (default behavior).
msg = _("Speech Unicode normalization default ({default})").format(
default=featureFlag.behaviorOfDefault.displayString
)
else:
# Translators: Used when reporting speech Unicode normalization state
# (disabled or enabled).
msg = _("Speech Unicode normalization {state}").format(
state=BoolFlag[nextName].displayString
)
ui.message(msg)

_tempEnableScreenCurtain = True
_waitingOnScreenCurtainWarningDialog: Optional[wx.Dialog] = None
_toggleScreenCurtainMessage: Optional[str] = None
Expand Down
27 changes: 16 additions & 11 deletions source/gui/nvdaControls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: UTF-8 -*-
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2016-2024 NV Access Limited, Derek Riemer, Cyrille Bougot, Luke Davis
# Copyright (C) 2016-2024 NV Access Limited, Derek Riemer, Cyrille Bougot, Luke Davis, Leonard de Ruijter
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
import collections
Expand Down Expand Up @@ -426,16 +425,18 @@ def __init__(
style=0,
validator=wx.DefaultValidator,
name=wx.ChoiceNameStr,
onChoiceEventHandler: typing.Callable[[wx.CommandEvent], None] | None = None,
):
"""
@param parent: The parent window.
@param keyPath: The list of keys required to get to the config value.
@param conf: The config.conf object.
@param pos: The position of the control. Forwarded to wx.Choice
@param size: The size of the control. Forwarded to wx.Choice
@param style: The style of the control. Forwarded to wx.Choice
@param validator: The validator for the control. Forwarded to wx.Choice
@param name: The name of the control. Forwarded to wx.Choice
:param parent: The parent window.
:param keyPath: The list of keys required to get to the config value.
:param conf: The config.conf object.
:param pos: The position of the control. Forwarded to wx.Choice
:param size: The size of the control. Forwarded to wx.Choice
:param style: The style of the control. Forwarded to wx.Choice
:param validator: The validator for the control. Forwarded to wx.Choice
:param name: The name of the control. Forwarded to wx.Choice
:param onChoiceEventHandler: Event handler bound for EVT_CHOICE
"""
self._confPath = keyPath
self._conf = conf
Expand All @@ -462,7 +463,11 @@ def __init__(
validator=validator,
name=name,
)

if onChoiceEventHandler is not None:
self.Bind(
wx.EVT_CHOICE,
onChoiceEventHandler
)
self.SetSelection(self._getChoiceIndex(configValue.value))
self.defaultValue = self._getConfSpecDefaultValue()
"""The default value of the config spec. Not the "behavior of default".
Expand Down
24 changes: 24 additions & 0 deletions source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,9 +1597,24 @@ def makeSettings(self, settingsSizer):
wxCtrlClass=nvdaControls.FeatureFlagCombo,
keyPath=["speech", "unicodeNormalization"],
conf=config.conf,
onChoiceEventHandler=self._onUnicodeNormalizationChange,
)
self.bindHelpEvent("SpeechUnicodeNormalization", self.unicodeNormalizationCombo)

# Translators: This is the label for a checkbox in the
# speech settings panel.
reportNormalizedForCharacterNavigationText = _("Report &Normalized when navigating by character")
Comment thread
seanbudd marked this conversation as resolved.
Resolved
self.reportNormalizedForCharacterNavigationCheckBox = settingsSizerHelper.addItem(
wx.CheckBox(self, label=reportNormalizedForCharacterNavigationText)
)
self.bindHelpEvent(
"SpeechReportNormalizedForCharacterNavigation",
self.reportNormalizedForCharacterNavigationCheckBox
)
self.reportNormalizedForCharacterNavigationCheckBox.SetValue(
config.conf["speech"]["reportNormalizedForCharacterNavigation"]
)

includeCLDRText = _(
# Translators: This is the label for a checkbox in the
# voice settings panel (if checked, data from the unicode CLDR will be used
Expand Down Expand Up @@ -1713,6 +1728,9 @@ def onSave(self):
].value
config.conf["speech"]["trustVoiceLanguage"] = self.trustVoiceLanguageCheckbox.IsChecked()
self.unicodeNormalizationCombo.saveCurrentValueToConf()
config.conf["speech"]["reportNormalizedForCharacterNavigation"] = (
self.reportNormalizedForCharacterNavigationCheckBox.IsChecked()
)
currentIncludeCLDR = config.conf["speech"]["includeCLDR"]
config.conf["speech"]["includeCLDR"] = newIncludeCldr = self.includeCLDRCheckbox.IsChecked()
if currentIncludeCLDR is not newIncludeCldr:
Expand Down Expand Up @@ -1753,6 +1771,12 @@ def _onSpeechModesListChange(self, evt: wx.CommandEvent):
+ [self._allSpeechModes.index(speech.SpeechMode.talk)]
)

def _onUnicodeNormalizationChange(self, evt: wx.CommandEvent):
evt.Skip()
self.reportNormalizedForCharacterNavigationCheckBox.Enable(
bool(self.unicodeNormalizationCombo._getControlCurrentFlag())
)

def isValid(self) -> bool:
enabledSpeechModes = self.speechModesList.CheckedItems
if len(enabledSpeechModes) < 2:
Expand Down
20 changes: 19 additions & 1 deletion source/speech/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: UTF-8 -*-
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
Expand Down Expand Up @@ -202,6 +201,25 @@ class EndUtteranceCommand(SpeechCommand):
def __repr__(self):
return "EndUtteranceCommand()"


class SuppressUnicodeNormalizationCommand(SpeechCommand):
"""Suppresses Unicode normalization at a point in a speech sequence.
For any text after this, Unicode normalization will be suppressed when state is True.
When state is False, original behavior of normalization will be restored.
This command is a no-op when normalization is disabled.
"""
state: bool

def __init__(self, state: bool = True):
"""
:param state: Suppress normalization if True, don't suppress when False
"""
self.state = state

def __repr__(self):
return f"SuppressUnicodeNormalizationCommand({self.state!r})"


class BaseProsodyCommand(SynthParamCommand):
"""Base class for commands which change voice prosody; i.e. pitch, rate, etc.
The change to the setting is specified using either an offset or a multiplier, but not both.
Expand Down
3 changes: 3 additions & 0 deletions source/speech/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Commands that are used in this file.
EndUtteranceCommand,
LangChangeCommand,
SuppressUnicodeNormalizationCommand,
SynthParamCommand,
BaseCallbackCommand,
ConfigProfileTriggerCommand,
Expand Down Expand Up @@ -363,6 +364,8 @@ def _processSpeechSequence(self, inSeq: SpeechSequence):
continue
if isinstance(command, SynthParamCommand):
paramTracker.update(command)
if isinstance(command, SuppressUnicodeNormalizationCommand):
continue # Not handled by speech manager
outSeq.append(command)
# Add the last sequence and make sure the sequence ends the utterance.
self._ensureEndUtterance(outSeq, outSeqs, paramsToReplay, paramTracker)
Expand Down
Loading