Skip to content

Commit f09d04b

Browse files
authored
Merge pull request #36 from NSoiffer/beep
Beep
2 parents 1cd616d + 3f81feb commit f09d04b

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

NVDA-addon/addon/globalPlugins/MathCAT/MathCAT.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,43 +68,56 @@ def ConvertSSMLTextForNVDA(text, language=""):
6868
wpm = synth._percentToParam(synth.rate, 80, 450)
6969
breakMulti = 180.0 / wpm
7070
synthConfig = config.conf["speech"][synth.name]
71+
supported_commands = synth.supportedCommands
72+
use_break = BreakCommand in supported_commands
73+
use_pitch = PitchCommand in supported_commands
74+
use_phoneme = PhonemeCommand in supported_commands
75+
use_character = CharacterModeCommand in supported_commands
7176
out = []
7277
if language:
7378
out.append(LangChangeCommand(language))
7479
resetProsody = set()
7580
for m in RE_MP_SPEECH.finditer(text):
7681
if m.lastgroup == "break":
77-
out.append(BreakCommand(time=int(m.group("break")) * breakMulti))
82+
if use_break:
83+
out.append(BreakCommand(time=int(m.group("break")) * breakMulti))
7884
elif m.lastgroup == "char":
7985
# get the NVDA settings for what to do for a capital char and apply them
8086
ch = m.group("char")
8187
if ch.isupper():
8288
if synthConfig["sayCapForCapitals"]:
8389
out.append(_(u"cap")) # capital letter prefix
84-
out.append(PitchCommand(multiplier=int(synthConfig["capPitchChange"])))
90+
if use_pitch:
91+
out.append(PitchCommand(multiplier=int(synthConfig["capPitchChange"])))
8592
if synthConfig["beepForCapitals"]:
8693
out.append(BeepCommand(2000, 50))
87-
out.extend((CharacterModeCommand(True), ch, CharacterModeCommand(False)))
88-
if ch.isupper():
94+
if use_character:
95+
out.extend((CharacterModeCommand(True), ch, CharacterModeCommand(False)))
96+
else:
97+
out.extend((" ", ch, " "))
98+
if use_pitch and ch.isupper():
8999
out.append(PitchCommand(multiplier=1))
90100
elif m.lastgroup == "comma":
91-
out.append(BreakCommand(time=100))
101+
if use_break:
102+
out.append(BreakCommand(time=100))
92103
elif m.lastgroup in PROSODY_COMMANDS:
93104
command = PROSODY_COMMANDS[m.lastgroup]
94-
out.append(command(multiplier=int(m.group(m.lastgroup)) / 100.0))
95-
resetProsody.add(command)
105+
if command in supported_commands:
106+
out.append(command(multiplier=int(m.group(m.lastgroup)) / 100.0))
107+
resetProsody.add(command)
96108
elif m.lastgroup == "prosodyReset":
97-
for command in resetProsody:
109+
for command in resetProsody: # only supported commands were added, so no need to check
98110
out.append(command(multiplier=1))
99111
resetProsody.clear()
100112
elif m.lastgroup == "phonemeText":
101-
out.append(PhonemeCommand(m.group("ipa"), text=m.group("phonemeText")))
113+
if use_phoneme:
114+
out.append(PhonemeCommand(m.group("ipa"), text=m.group("phonemeText")))
115+
else:
116+
out.append(m.group("phonemeText"))
102117
elif m.lastgroup == "content":
103118
# MathCAT puts out spaces between words, the speak command seems to want to glom the strings together at times,
104119
# so we need to add individual " "s to the output
105-
out.append(" ")
106-
out.append(m.group(0))
107-
out.append(" ")
120+
out.extend((" ", m.group(0), " "))
108121

109122
if language:
110123
out.append(LangChangeCommand(None))
@@ -297,12 +310,21 @@ def getSpeechForMathMl(self, mathml):
297310
speech.speakMessage(_("Illegal MathML found: see NVDA error log for details"))
298311
libmathcat.SetMathML("<math></math>") # set it to something
299312
try:
300-
return ConvertSSMLTextForNVDA(libmathcat.GetSpokenText())
313+
if self._add_sounds():
314+
return [BeepCommand(800,25)] + ConvertSSMLTextForNVDA(libmathcat.GetSpokenText()) + [BeepCommand(600,15)]
315+
else:
316+
return ConvertSSMLTextForNVDA(libmathcat.GetSpokenText())
317+
301318
except Exception as e:
302319
log.error(e)
303320
speech.speakMessage(_("Error in speaking math: see NVDA error log for details"))
304321
return [""]
305322

323+
def _add_sounds(self):
324+
try:
325+
return libmathcat.GetPreference("SpeechSound") != "None"
326+
except:
327+
return False
306328

307329
def getBrailleForMathMl(self, mathml):
308330
# log.info("***MathCAT getBrailleForMathMl")

NVDA-addon/buildVars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _(arg):
2929
The initial version of MathCAT is English-only but is designed with translations in mind.
3030
"""),
3131
# version
32-
"addon_version": "0.1.10",
32+
"addon_version": "0.1.11",
3333
# Author(s)
3434
"addon_author": "Neil Soiffer <soiffer@alum.mit.edu>",
3535
# URL for the add-on documentation support

0 commit comments

Comments
 (0)