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 = 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":
			out.append(speech.BreakCommand(time=int(m.group("break")) * breakMulti))
		elif m.lastgroup == "char":
			out.extend((speech.CharacterModeCommand(True),
				m.group("char"), speech.CharacterModeCommand(False)))
		elif m.lastgroup == "comma":
			out.append(speech.BreakCommand(time=100))
		elif m.lastgroup in PROSODY_COMMANDS:
			command = PROSODY_COMMANDS[m.lastgroup]
			out.append(command(multiplier=int(m.group(m.lastgroup)) / 100.0))
			resetProsody.add(command)
		elif m.lastgroup == "prosodyReset":
			for command in resetProsody:
				out.append(command(multiplier=1))
			resetProsody.clear()
		elif m.lastgroup == "phonemeText":
			out.append(speech.PhonemeCommand(m.group("ipa"),
				text=m.group("phonemeText")))
		elif m.lastgroup == "content":
			out.append(m.group(0))
	if language:
		out.append(speech.LangChangeCommand(None))
	return out
    def test_convertComplex(self):
        """Test converting a complex speech sequence to SSML.
		XML generation is already tested by TestXmlBalancer.
		However, SSML is what callers expect at the end of the day,
		so test converting a complex speech sequence to SSML.
		Depends on behavior tested by TestXmlBalancer.
		"""
        converter = speechXml.SsmlConverter("en_US")
        xml = converter.convertToXml([
            "t1",
            speech.PitchCommand(multiplier=2),
            speech.VolumeCommand(multiplier=2), "t2",
            speech.PitchCommand(),
            speech.LangChangeCommand("de_DE"),
            speech.CharacterModeCommand(True),
            speech.IndexCommand(1), "c",
            speech.CharacterModeCommand(False),
            speech.PhonemeCommand("phIpa", text="phText")
        ])
        self.assertEqual(
            xml,
            '<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">'
            't1'
            '<prosody pitch="200%" volume="200%">t2</prosody>'
            '<prosody volume="200%"><voice xml:lang="de-DE">'
            '<mark name="1"/><say-as interpret-as="characters">c</say-as>'
            '<phoneme alphabet="ipa" ph="phIpa">phText</phoneme>'
            '</voice></prosody></speak>')