Skip to content

Commit 03ac978

Browse files
authored
Merge 984c796 into db664be
2 parents db664be + 984c796 commit 03ac978

16 files changed

Lines changed: 189 additions & 162 deletions

File tree

source/mathPres/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def getSpeechForMathMl(self, mathMl):
3333
@param mathMl: The MathML markup.
3434
@type mathMl: str
3535
@return: A speech sequence.
36-
@rtype: List[str, speech.SpeechCommand]
36+
@rtype: List[str, commands.SpeechCommand]
3737
"""
3838
raise NotImplementedError
3939

source/mathPres/mathPlayer.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
import braille
1919
import mathPres
2020

21+
from speech.commands import (
22+
PitchCommand,
23+
VolumeCommand,
24+
RateCommand,
25+
LangChangeCommand,
26+
BreakCommand,
27+
CharacterModeCommand,
28+
PhonemeCommand,
29+
)
30+
2131
RE_MP_SPEECH = re.compile(
2232
# Break.
2333
r"<break time='(?P<break>\d+)ms'/> ?"
@@ -35,9 +45,9 @@
3545
# Actual content.
3646
r"|(?P<content>[^<,]+)")
3747
PROSODY_COMMANDS = {
38-
"pitch": speech.PitchCommand,
39-
"volume": speech.VolumeCommand,
40-
"rate": speech.RateCommand,
48+
"pitch": PitchCommand,
49+
"volume": VolumeCommand,
50+
"rate": RateCommand,
4151
}
4252
def _processMpSpeech(text, language):
4353
# MathPlayer's default rate is 180 wpm.
@@ -47,16 +57,16 @@ def _processMpSpeech(text, language):
4757
breakMulti = 180.0 / wpm
4858
out = []
4959
if language:
50-
out.append(speech.LangChangeCommand(language))
60+
out.append(LangChangeCommand(language))
5161
resetProsody = set()
5262
for m in RE_MP_SPEECH.finditer(text):
5363
if m.lastgroup == "break":
54-
out.append(speech.BreakCommand(time=int(m.group("break")) * breakMulti))
64+
out.append(BreakCommand(time=int(m.group("break")) * breakMulti))
5565
elif m.lastgroup == "char":
56-
out.extend((speech.CharacterModeCommand(True),
57-
m.group("char"), speech.CharacterModeCommand(False)))
66+
out.extend((CharacterModeCommand(True),
67+
m.group("char"), CharacterModeCommand(False)))
5868
elif m.lastgroup == "comma":
59-
out.append(speech.BreakCommand(time=100))
69+
out.append(BreakCommand(time=100))
6070
elif m.lastgroup in PROSODY_COMMANDS:
6171
command = PROSODY_COMMANDS[m.lastgroup]
6272
out.append(command(multiplier=int(m.group(m.lastgroup)) / 100.0))
@@ -66,12 +76,12 @@ def _processMpSpeech(text, language):
6676
out.append(command(multiplier=1))
6777
resetProsody.clear()
6878
elif m.lastgroup == "phonemeText":
69-
out.append(speech.PhonemeCommand(m.group("ipa"),
79+
out.append(PhonemeCommand(m.group("ipa"),
7080
text=m.group("phonemeText")))
7181
elif m.lastgroup == "content":
7282
out.append(m.group(0))
7383
if language:
74-
out.append(speech.LangChangeCommand(None))
84+
out.append(LangChangeCommand(None))
7585
return out
7686

7787
class MathPlayerInteraction(mathPres.MathInteractionNVDAObject):

source/sayAllHandler.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import queueHandler
1616
import winKernel
1717

18+
from speech.commands import CallbackCommand, EndUtteranceCommand
19+
1820
CURSOR_CARET = 0
1921
CURSOR_REVIEW = 1
2022

@@ -69,8 +71,8 @@ def next(self):
6971
if not obj:
7072
return
7173
# Call this method again when we start speaking this object.
72-
callbackCommand = speech.CallbackCommand(self.next, name="say-all:next")
73-
speech.speakObject(obj, reason=controlTypes.OutputReason.SAYALL, _prefixSpeechCommand=callbackCommand)
74+
callbackCommand = CallbackCommand(self.next, name="say-all:next")
75+
speakObject(obj, reason=controlTypes.OutputReason.SAYALL, _prefixSpeechCommand=callbackCommand)
7476

7577
def stop(self):
7678
self.walker = None
@@ -148,8 +150,8 @@ def nextLine(self):
148150
# No more text.
149151
if isinstance(self.reader.obj, textInfos.DocumentWithPageTurns):
150152
# Once the last line finishes reading, try turning the page.
151-
cb = speech.CallbackCommand(self.turnPage, name="say-all:turnPage")
152-
speech.speakWithoutPauses([cb, speech.EndUtteranceCommand()])
153+
cb = CallbackCommand(self.turnPage, name="say-all:turnPage")
154+
speech.speakWithoutPauses([cb, EndUtteranceCommand()])
153155
else:
154156
self.finish()
155157
return
@@ -163,7 +165,7 @@ def nextLine(self):
163165
def _onLineReached(obj=self.reader.obj, state=state):
164166
self.lineReached(obj, bookmark, state)
165167

166-
cb = speech.CallbackCommand(
168+
cb = CallbackCommand(
167169
_onLineReached,
168170
name="say-all:lineReached"
169171
)
@@ -239,11 +241,11 @@ def finish(self):
239241
# Otherwise, if a different synth is being used for say all,
240242
# we might switch synths too early and truncate the final speech.
241243
# We do this by putting a CallbackCommand at the start of a new utterance.
242-
cb = speech.CallbackCommand(self.stop, name="say-all:stop")
244+
cb = CallbackCommand(self.stop, name="say-all:stop")
243245
speech.speakWithoutPauses([
244-
speech.EndUtteranceCommand(),
246+
EndUtteranceCommand(),
245247
cb,
246-
speech.EndUtteranceCommand()
248+
EndUtteranceCommand()
247249
])
248250

249251
def stop(self):

source/speech/__init__.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,7 @@
3434
EndUtteranceCommand,
3535
CharacterModeCommand,
3636
)
37-
from .commands import ( # noqa: F401
38-
# F401 imported but unused:
39-
# The following are imported here because other files that speech.py
40-
# previously relied on "import * from .commands"
41-
# New commands added to commands.py should be directly imported only where needed.
42-
# Usage of these imports is deprecated and will be removed in 2021.1
43-
SynthCommand,
44-
IndexCommand,
45-
SynthParamCommand,
46-
BreakCommand,
47-
BaseProsodyCommand,
48-
VolumeCommand,
49-
RateCommand,
50-
PhonemeCommand,
51-
BaseCallbackCommand,
52-
CallbackCommand,
53-
WaveFileCommand,
54-
ConfigProfileTriggerCommand,
55-
)
37+
5638
from . import types
5739
from .types import (
5840
SpeechSequence,

source/speech/manager.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,7 @@
1818
IndexCommand,
1919
_CancellableSpeechCommand,
2020
)
21-
from .commands import ( # noqa: F401
22-
# F401 imported but unused:
23-
# These are imported explicitly to maintain backwards compatibility and will be removed in
24-
# 2021.1. Rather than rely on these imports, import directly from the commands module.
25-
# New commands added to commands.py should be directly imported only where needed.
26-
SpeechCommand,
27-
PitchCommand,
28-
LangChangeCommand,
29-
BeepCommand,
30-
CharacterModeCommand,
31-
SynthCommand,
32-
BreakCommand,
33-
BaseProsodyCommand,
34-
VolumeCommand,
35-
RateCommand,
36-
PhonemeCommand,
37-
CallbackCommand,
38-
WaveFileCommand,
39-
)
21+
4022
from .priorities import Spri, SPEECH_PRIORITIES
4123
from logHandler import log
4224
from synthDriverHandler import getSynth

source/speechXml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from collections import namedtuple, OrderedDict
1414
import re
1515
import speech
16+
from speech.commands import SpeechCommand
1617
from logHandler import log
1718

1819
XML_ESCAPES = {
@@ -196,7 +197,7 @@ class SpeechXmlConverter(object):
196197
Subclasses implement specific XML schemas by implementing methods which convert each speech command.
197198
The method for a speech command should be named with the prefix "convert" followed by the command's class name.
198199
For example, the handler for C{IndexCommand} should be named C{convertIndexCommand}.
199-
These methods receive the L{speech.SpeechCommand} instance as their only argument.
200+
These methods receive the L{SpeechCommand} instance as their only argument.
200201
They should return an appropriate XmlBalancer command.
201202
Subclasses may wish to extend L{generateBalancerCommands}
202203
to produce additional XmlBalancer commands at the start or end;
@@ -210,7 +211,7 @@ def generateBalancerCommands(self, speechSequence):
210211
for item in speechSequence:
211212
if isinstance(item, str):
212213
yield item
213-
elif isinstance(item, speech.SpeechCommand):
214+
elif isinstance(item, SpeechCommand):
214215
name = type(item).__name__
215216
# For example: self.convertIndexCommand
216217
func = getattr(self, "convert%s" % name, None)

source/synthDriverHandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SynthDriver(driverHandler.Driver):
6262
e.g. the L{voice} attribute is used for the L{voice} setting.
6363
These will usually be properties.
6464
L{supportedCommands} should specify what synth commands the synthesizer supports.
65-
At a minimum, L{speech.IndexCommand} must be supported.
65+
At a minimum, L{IndexCommand} must be supported.
6666
L{PitchCommand} must also be supported if you want capital pitch change to work;
6767
support for the pitch setting is not sufficient.
6868
L{supportedNotifications} should specify what notifications the synthesizer provides.
@@ -93,7 +93,7 @@ class SynthDriver(driverHandler.Driver):
9393
#: @type: str
9494
description = ""
9595
#: The speech commands supported by the synth.
96-
#: @type: set of L{speech.SynthCommand} subclasses.
96+
#: @type: set of L{commands.SynthCommand} subclasses.
9797
supportedCommands = frozenset()
9898
#: The notifications provided by the synth.
9999
#: @type: set of L{extensionPoints.Action} instances

source/synthDrivers/espeak.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
from logHandler import log
1616
from driverHandler import BooleanDriverSetting
1717

18+
from speech.commands import (
19+
IndexCommand,
20+
CharacterModeCommand,
21+
LangChangeCommand,
22+
BreakCommand,
23+
PitchCommand,
24+
RateCommand,
25+
VolumeCommand,
26+
PhonemeCommand,
27+
)
28+
1829
class SynthDriver(SynthDriver):
1930
name = "espeak"
2031
description = "eSpeak NG"
@@ -29,14 +40,14 @@ class SynthDriver(SynthDriver):
2940
SynthDriver.VolumeSetting(),
3041
)
3142
supportedCommands = {
32-
speech.IndexCommand,
33-
speech.CharacterModeCommand,
34-
speech.LangChangeCommand,
35-
speech.BreakCommand,
36-
speech.PitchCommand,
37-
speech.RateCommand,
38-
speech.VolumeCommand,
39-
speech.PhonemeCommand,
43+
IndexCommand,
44+
CharacterModeCommand,
45+
LangChangeCommand,
46+
BreakCommand,
47+
PitchCommand,
48+
RateCommand,
49+
VolumeCommand,
50+
PhonemeCommand,
4051
}
4152
supportedNotifications = {synthIndexReached, synthDoneSpeaking}
4253

@@ -60,9 +71,9 @@ def _get_language(self):
6071
return self._language
6172

6273
PROSODY_ATTRS = {
63-
speech.PitchCommand: "pitch",
64-
speech.VolumeCommand: "volume",
65-
speech.RateCommand: "rate",
74+
PitchCommand: "pitch",
75+
VolumeCommand: "volume",
76+
RateCommand: "rate",
6677
}
6778

6879
IPA_TO_ESPEAK = {
@@ -91,16 +102,16 @@ def speak(self,speechSequence):
91102
for item in speechSequence:
92103
if isinstance(item,str):
93104
textList.append(self._processText(item))
94-
elif isinstance(item,speech.IndexCommand):
105+
elif isinstance(item, IndexCommand):
95106
textList.append("<mark name=\"%d\" />"%item.index)
96-
elif isinstance(item,speech.CharacterModeCommand):
107+
elif isinstance(item, CharacterModeCommand):
97108
textList.append("<say-as interpret-as=\"characters\">" if item.state else "</say-as>")
98-
elif isinstance(item,speech.LangChangeCommand):
109+
elif isinstance(item, LangChangeCommand):
99110
if langChanged:
100111
textList.append("</voice>")
101112
textList.append("<voice xml:lang=\"%s\">"%(item.lang if item.lang else defaultLanguage).replace('_','-'))
102113
langChanged=True
103-
elif isinstance(item,speech.BreakCommand):
114+
elif isinstance(item, BreakCommand):
104115
textList.append('<break time="%dms" />' % item.time)
105116
elif type(item) in self.PROSODY_ATTRS:
106117
if prosody:
@@ -121,7 +132,7 @@ def speak(self,speechSequence):
121132
for attr,val in prosody.items():
122133
textList.append(' %s="%d%%"'%(attr,val))
123134
textList.append(">")
124-
elif isinstance(item,speech.PhonemeCommand):
135+
elif isinstance(item, PhonemeCommand):
125136
# We can't use str.translate because we want to reject unknown characters.
126137
try:
127138
phonemes="".join([self.IPA_TO_ESPEAK[char] for char in item.ipa])

source/synthDrivers/oneCore.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525
import winVersion
2626
import NVDAHelper
2727

28+
from speech.commands import (
29+
IndexCommand,
30+
CharacterModeCommand,
31+
LangChangeCommand,
32+
BreakCommand,
33+
PitchCommand,
34+
RateCommand,
35+
VolumeCommand,
36+
PhonemeCommand,
37+
)
38+
2839
#: The number of 100-nanosecond units in 1 second.
2940
HUNDRED_NS_PER_SEC = 10000000 # 1000000000 ns per sec / 100 ns
3041
ocSpeech_Callback = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int, ctypes.c_wchar_p)
@@ -78,9 +89,9 @@ def generateBalancerCommands(self, speechSequence):
7889
yield next(commands)
7990
# OneCore didn't provide a way to set base prosody values before API version 5.
8091
# Therefore, the base values need to be set using SSML.
81-
yield self.convertRateCommand(speech.RateCommand(multiplier=1))
82-
yield self.convertVolumeCommand(speech.VolumeCommand(multiplier=1))
83-
yield self.convertPitchCommand(speech.PitchCommand(multiplier=1))
92+
yield self.convertRateCommand(RateCommand(multiplier=1))
93+
yield self.convertVolumeCommand(VolumeCommand(multiplier=1))
94+
yield self.convertPitchCommand(PitchCommand(multiplier=1))
8495
for command in commands:
8596
yield command
8697

@@ -105,14 +116,14 @@ class SynthDriver(SynthDriver):
105116
# Translators: Description for a speech synthesizer.
106117
description = _("Windows OneCore voices")
107118
supportedCommands = {
108-
speech.IndexCommand,
109-
speech.CharacterModeCommand,
110-
speech.LangChangeCommand,
111-
speech.BreakCommand,
112-
speech.PitchCommand,
113-
speech.RateCommand,
114-
speech.VolumeCommand,
115-
speech.PhonemeCommand,
119+
IndexCommand,
120+
CharacterModeCommand,
121+
LangChangeCommand,
122+
BreakCommand,
123+
PitchCommand,
124+
RateCommand,
125+
VolumeCommand,
126+
PhonemeCommand,
116127
}
117128
supportedNotifications = {synthIndexReached, synthDoneSpeaking}
118129

source/synthDrivers/sapi4.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import nvwave
1818
import weakref
1919

20+
from speech.commands import IndexCommand, SpeechCommand, CharacterModeCommand
2021

2122
class SynthDriverBufSink(COMObject):
2223
_com_interfaces_ = [ITTSBufNotifySink]
@@ -96,16 +97,16 @@ def speak(self,speechSequence):
9697
for item in speechSequence:
9798
if isinstance(item,str):
9899
textList.append(item.replace('\\','\\\\'))
99-
elif isinstance(item,speech.IndexCommand):
100+
elif isinstance(item, IndexCommand):
100101
textList.append("\\mrk=%d\\"%item.index)
101-
elif isinstance(item,speech.CharacterModeCommand):
102+
elif isinstance(item, CharacterModeCommand):
102103
textList.append("\\RmS=1\\" if item.state else "\\RmS=0\\")
103104
charMode=item.state
104-
elif isinstance(item,speech.SpeechCommand):
105+
elif isinstance(item, SpeechCommand):
105106
log.debugWarning("Unsupported speech command: %s"%item)
106107
else:
107108
log.error("Unknown speech: %s"%item)
108-
if isinstance(item,speech.IndexCommand):
109+
if isinstance(item, IndexCommand):
109110
# This is the index denoting the end of the speech sequence.
110111
self._finalIndex=item.index
111112
if charMode:

0 commit comments

Comments
 (0)