Пример #1
0
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
Пример #2
0
 def speakMatrix(self):
     matrix = [
         "Matrix %d" % self.matrixNumber, "Begin matrix",
         speech.BreakCommand(400)
     ]
     for i in range(1, self.matrix.rows + 1):
         matrix += self.speakRow(i)
         matrix.append(speech.BreakCommand(300))
     speech.speak(matrix + ["end matrix"])
Пример #3
0
 def speakRow(self, row):
     temp = ["row " + str(row) + ": ", speech.BreakCommand(300)]
     #This unfortunately is very buggie on espeak, so I'm removing it for now.
     #temp.append(speech.PitchCommand(1.25))
     for i in xrange(1, self.matrix.columns + 1):
         temp += [
             str(self.matrix.get_cell(row, i)),
             speech.BreakCommand(180)
         ]
     #temp.append(speech.PitchCommand(0.25))
     return temp
Пример #4
0
    def patchedSpaceSpeechSequence(self, speechSequence):
        if not int(self._chinesespace) == 0:
            joinString = ""
            tempSpeechSequence = []
            for command in speechSequence:
                if not isinstance(command, str):
                    tempSpeechSequence.append(joinString)
                    tempSpeechSequence.append(command)
                    joinString = ""
                else:
                    joinString += command
            tempSpeechSequence.append(joinString)
            speechSequence = tempSpeechSequence

            tempSpeechSequence = []
            for command in speechSequence:
                if isinstance(command, str):
                    result = re.split(chinese_space_pattern, command)
                    if len(result) == 1:
                        tempSpeechSequence.append(command)
                    else:
                        temp = []
                        for i in result:
                            temp.append(i)
                            temp.append(
                                speech.BreakCommand(
                                    int(self._chinesespace) * 5))
                        temp = temp[:-1]
                        tempSpeechSequence += temp
                else:
                    tempSpeechSequence.append(command)
            speechSequence = tempSpeechSequence
        return speechSequence
	def speakMathLine(self, spokenLine):
		spokenLine = EditableLatex.speech.translate (spokenLine)
		out = []
		sups = 0 #How many superscripts we are in.
		subs = 0 #How many subscripts we are in.
		for expr in MATH_MATCHER.finditer(spokenLine):
			if expr.group(1) == "sup":
				sups+=1
				#If there are any subscripts, do not pitch it, as we pitched the subscript.
				#If there are any superscripts nessted, don't pitch it, because voice control isn't good enough for this in NVDA.
				if sups == 1 and not subs:
					out.append(speech.PitchCommand(1.25))
				out.append("soop")
				out.append(speech.BreakCommand(200))
			elif expr.group(1) == "/sup":
				sups -= 1
				out.append("End soop")
				if not sups and not subs:
					#we know we are in nothing. turn the pitch change off.
					out.append(speech.PitchCommand(1))
				out.append(speech.BreakCommand(200))
			elif expr.group(1) == "sub":
				subs += 1
				if subs == 1 and sups == 0:
					out.append(speech.PitchCommand(.25))
				out.append("sub")
				out.append(speech.BreakCommand(200))
			elif expr.group(1) == "/sub":
				subs -= 1
				out.append("End sub")
				if not subs and not sups:
					out.append(speech.PitchCommand(1))
				out.append(speech.BreakCommand(200))
			else:
				#all other math. Send er.
				out.append(expr.group(0))
		speech.speak(out)
Пример #6
0
def translate_SpeechCommand(serializes):
    """
	convert Access8Math serialize object to SpeechCommand
	@param lines: source serializes
	@type list
	@rtype SpeechCommand
	"""
    pattern = re.compile(r'[@](?P<time>[\d]*)[@]')
    speechSequence = []
    for r in flatten(serializes):
        time_search = pattern.search(r)
        try:
            time = time_search.group('time')
            command = speech.BreakCommand(
                time=int(time) + int(os.environ['item_interval_time']))
            speechSequence.append(command)
        except:
            speechSequence.append(r)

    return speechSequence