Skip to content

Commit

Permalink
MathPlayer: Set the language based on the xml:lang attribute of the m…
Browse files Browse the repository at this point in the history
…ath tag, if any.
  • Loading branch information
jcsteh committed May 1, 2015
1 parent 471d09d commit 2dd48ca
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions source/mathPres/mathPlayer.py
Expand Up @@ -38,13 +38,15 @@
"volume": speech.VolumeCommand,
"rate": speech.RateCommand,
}
def _processMpSpeech(text):
def _processMpSpeech(text, language):
# MathPlayer's default rate is 180 wpm.
# Assume that 0% is 80 wpm and 100% is 450 wpm and scale accordingly.
synth = speech.getSynth()
wpm = synth._percentToParam(synth.rate, 80, 450)
breakMulti = 180.0 / wpm
out = []
if language:
out.append(speech.LangChangeCommand(language))
resetProsody = set()
for m in RE_MP_SPEECH.finditer(text):
if m.lastgroup == "break":
Expand All @@ -67,6 +69,8 @@ def _processMpSpeech(text):
text=m.group("phonemeText")))
elif m.lastgroup == "content":
out.append(m.group(0))
if language:
out.append(speech.LangChangeCommand(None))
return out

class MathPlayerInteraction(mathPres.MathInteractionNVDAObject):
Expand All @@ -78,7 +82,8 @@ def __init__(self, provider=None, mathMl=None):

def reportFocus(self):
super(MathPlayerInteraction, self).reportFocus()
speech.speak(_processMpSpeech(self.provider._mpSpeech.GetSpokenText()))
speech.speak(_processMpSpeech(self.provider._mpSpeech.GetSpokenText(),
self.provider._language))

def getBrailleRegions(self, review=False):
yield braille.NVDAObjectRegion(self, appendText=" ")
Expand Down Expand Up @@ -108,7 +113,7 @@ def script_navigate(self, gesture):
"shift" in modNames, "control" in modNames, "alt" in modNames, False)
except COMError:
return
speech.speak(_processMpSpeech(text))
speech.speak(_processMpSpeech(text, self.provider._language))

class MathPlayer(mathPres.MathPresentationProvider):

Expand All @@ -120,13 +125,16 @@ def __init__(self):
self._mpBraille = mpSpeech.QueryInterface(IMathBraille)

def _setSpeechLanguage(self, mathMl):
lang = speech.getCurrentLanguage()
lang = mathPres.getLanguageFromMath(mathMl)
if not lang:
lang = speech.getCurrentLanguage()
self._mpSpeechSettings.SetLanguage(lang.replace("_", "-"))
self._language = lang

def getSpeechForMathMl(self, mathMl):
self._setSpeechLanguage(mathMl)
self._mpSpeech.SetMathML(mathMl)
return _processMpSpeech(self._mpSpeech.GetSpokenText())
return _processMpSpeech(self._mpSpeech.GetSpokenText(), self._language)

def getBrailleForMathMl(self, mathMl):
self._mpSpeech.SetMathML(mathMl)
Expand Down

0 comments on commit 2dd48ca

Please sign in to comment.