Example #1
0
	def getFormattedCandidateDescription(self,candidate):
		descriptions=[]
		numSymbols=len(candidate) if candidate else 0
		if numSymbols!=1: return u""
		symbol=candidate[0]
		try:
			symbolDescriptions=characterProcessing.getCharacterDescription(speech.getCurrentLanguage(),symbol) or []
		except TypeError:
			symbolDescriptions=[]
		if config.conf["inputComposition"]["alwaysIncludeShortCharacterDescriptionInCandidateName"]:
			symbolDescriptions=symbolDescriptions[1:]
		if len(symbolDescriptions)<1: return u""
		return u", ".join(symbolDescriptions)
Example #2
0
	def getFormattedCandidateName(self,number,candidate):
		if config.conf["inputComposition"]["alwaysIncludeShortCharacterDescriptionInCandidateName"]:
			describedSymbols=[]
			for symbol in candidate:
				try:
					symbolDescriptions=characterProcessing.getCharacterDescription(speech.getCurrentLanguage(),symbol) or []
				except TypeError:
					symbolDescriptions=[]
				if len(symbolDescriptions)>=1:
					description=symbolDescriptions[0]
					if description.startswith('(') and description.endswith(')'):
						describedSymbols.append(description[1:-1])
					else:
						# Translators: a message announcing a candidate's character and description.
						describedSymbols.append(_(u"{symbol} as in {description}").format(symbol=symbol,description=description))
				else:
					describedSymbols.append(symbol)
			candidate=u", ".join(describedSymbols)
		# Translators: a formatted message announcing a candidate's number and candidate text.
		return _(u"{number} {candidate}").format(number=number,candidate=candidate)
Example #3
0
	def getFormattedCandidateName(self,number,candidate):
		if config.conf["inputComposition"]["alwaysIncludeShortCharacterDescriptionInCandidateName"]:
			describedSymbols=[]
			for symbol in candidate:
				try:
					symbolDescriptions=characterProcessing.getCharacterDescription(speech.getCurrentLanguage(),symbol) or []
				except TypeError:
					symbolDescriptions=[]
				if len(symbolDescriptions)>=1:
					description=symbolDescriptions[0]
					if description.startswith('(') and description.endswith(')'):
						describedSymbols.append(description[1:-1])
					else:
						# Translators: a message announcing a candidate's character and description.
						describedSymbols.append(_(u"{symbol} as in {description}").format(symbol=symbol,description=description))
				else:
					describedSymbols.append(symbol)
			candidate=u", ".join(describedSymbols)
		# Translators: a formatted message announcing a candidate's number and candidate text.
		return _(u"{number} {candidate}").format(number=number,candidate=candidate)
    def postProcessSynchronousCommands(self, speechSequence, symbolLevel):
        language = speech.getCurrentLanguage()
        speechSequence = [
            element for element in speechSequence
            if not isinstance(element, str) or not speech.isBlank(
                speech.processText(language, element, symbolLevel))
        ]

        newSequence = []
        for (isSynchronous, values) in itertools.groupby(
                speechSequence,
                key=lambda x: isinstance(x, PpSynchronousCommand)):
            if isSynchronous:
                chain = PpChainCommand(list(values))
                duration = chain.getDuration()
                newSequence.append(chain)
                newSequence.append(speech.commands.BreakCommand(duration))
            else:
                newSequence.extend(values)
        newSequence = self.eloquenceFix(newSequence, language, symbolLevel)
        return newSequence
Example #5
0
 def getFormattedCandidateName(self, number, candidate):
     #nvdajp begin
     import jpUtils
     if config.conf["keyboard"]["nvdajpEnableKeyEvents"]:
         fb = (braille.handler.displaySize > 0)
         c = jpUtils.getDiscriminantReading(candidate, forBraille=fb)
         log.debug(u"{number} {candidate} {c}".format(number=number,
                                                      candidate=candidate,
                                                      c=c))
         if config.conf["language"]["announceCandidateNumber"]:
             return _(u"{number} {candidate}").format(number=number,
                                                      candidate=c)
         return c
     #nvdajp end
     if config.conf["inputComposition"][
             "alwaysIncludeShortCharacterDescriptionInCandidateName"]:
         describedSymbols = []
         for symbol in candidate:
             try:
                 symbolDescriptions = characterProcessing.getCharacterDescription(
                     speech.getCurrentLanguage(), symbol) or []
             except TypeError:
                 symbolDescriptions = []
             if len(symbolDescriptions) >= 1:
                 description = symbolDescriptions[0]
                 if description.startswith('(') and description.endswith(
                         ')'):
                     describedSymbols.append(description[1:-1])
                 else:
                     # Translators: a message announcing a candidate's character and description.
                     describedSymbols.append(
                         _(u"{symbol} as in {description}").format(
                             symbol=symbol, description=description))
             else:
                 describedSymbols.append(symbol)
         candidate = u", ".join(describedSymbols)
     # Translators: a formatted message announcing a candidate's number and candidate text.
     return _(u"{number} {candidate}").format(number=number,
                                              candidate=candidate)
    def test(self, s, symbolLevel):
        wav = "H:\\drp\\work\\emacspeak\\sounds\\classic\\alarm.wav"
        wavLength = self.getWavLengthMillis(wav)
        language = speech.getCurrentLanguage()
        tone = 500

        while "!" in s:
            index = s.index("!")
            prefix = s[:index]
            prefix = prefix.lstrip()
            pPrefix = speech.processText(language, prefix, symbolLevel)
            if speech.isBlank(pPrefix):
                pass
            else:
                yield prefix
            #yield speech.commands.WaveFileCommand(wav)
            #yield speech.commands.BeepCommand(tone, 100)
            #yield PpBeepCommand(tone, 100)
            yield PpWaveFileCommand(wav)
            tone += 50
            #yield speech.commands.BreakCommand(100)
            s = s[index + 1:]
        if len(s) > 0:
            yield s
Example #7
0
def getCurrentLanguage():
    s = speech.getCurrentLanguage()
    return s[:2]
	def _setSpeechLanguage(self, mathMl):
		lang = mathPres.getLanguageFromMath(mathMl)
		if not lang:
			lang = speech.getCurrentLanguage()
		self._mpSpeechSettings.SetLanguage(lang.replace("_", "-"))
		self._language = lang
Example #9
0
	def _setSpeechLanguage(self, mathMl):
		lang = mathPres.getLanguageFromMath(mathMl)
		if not lang:
			lang = speech.getCurrentLanguage()
		self._mpSpeechSettings.SetLanguage(lang.replace("_", "-"))
		self._language = lang
Example #10
0
def custom_getSpellingSpeech(  # noqa: C901
        text: str,
        locale: Optional[str] = None,
        useCharacterDescriptions: bool = False):
    defaultLanguage = getCurrentLanguage()
    if not locale or (not config.conf['speech']['autoDialectSwitching'] and
                      locale.split('_')[0] == defaultLanguage.split('_')[0]):
        locale = defaultLanguage

    if not text:
        # Translators: This is spoken when NVDA moves to an empty line.
        yield _("blank")
        return
    if not text.isspace():
        text = text.rstrip()

    synth = synthDriverHandler.getSynth()
    synthConfig = config.conf["speech"][synth.name]
    charMode = False
    textLength = len(text)
    count = 0
    localeHasConjuncts = True if locale.split(
        '_', 1)[0] in LANGS_WITH_CONJUNCT_CHARS else False
    charDescList = getCharDescListFromText(
        text, locale) if localeHasConjuncts else text
    for item in charDescList:
        if localeHasConjuncts:
            # item is a tuple containing character and its description
            speakCharAs = item[0]
            charDesc = item[1]
        else:
            charDesc = None
            # item is just a character.
            speakCharAs = item
            if CJK["speechReview"] == "Off" and useCharacterDescriptions:
                charDesc = characterProcessing.getCharacterDescription(
                    locale, speakCharAs.lower())
            else:
                #do not speak character descriptions for alphanumeric characters unless the function is called by the review_currentCharacter method.
                #This is to prevent phonetic spelling of the alphabets when typing, and moving the caret and review cursor.
                if isAlphanumeric(
                        speakCharAs) and not CJK["isReviewCharacter"]:
                    #The cursor has moved, so reset the previously stored character.
                    #This allows  for a more consistent speech feedback by always speaking the phonetic spelling of alphanumeric characters first after the focus moves.
                    CJK["previousCharacter"] = ""
                elif CJK["speechReview"] == "On":
                    #Retrieve the character description one at a time.
                    charDesc = speechReview_getCharacterDescription(
                        locale, speakCharAs.lower())

            if charDesc and CJK["speechReview"] == "On":
                speakCharAs = "".join(charDesc)
            elif charDesc:
                IDEOGRAPHIC_COMMA = u"\u3001"
                speakCharAs = charDesc[
                    0] if textLength > 1 else IDEOGRAPHIC_COMMA.join(charDesc)
            else:
                speakCharAs = characterProcessing.processSpeechSymbol(
                    locale, speakCharAs)

        uppercase = speakCharAs.isupper()
        # if useCharacterDescriptions and charDesc:
        # IDEOGRAPHIC_COMMA = u"\u3001"
        # speakCharAs=charDesc[0] if textLength>1 else IDEOGRAPHIC_COMMA.join(charDesc)
        # else:
        # speakCharAs=characterProcessing.processSpeechSymbol(locale,speakCharAs)'''
        if uppercase and synthConfig["sayCapForCapitals"]:
            # Translators: cap will be spoken before the given letter when it is capitalized.
            speakCharAs = _("cap %s") % speakCharAs
        if uppercase and synth.isSupported(
                "pitch") and synthConfig["capPitchChange"]:
            yield PitchCommand(offset=synthConfig["capPitchChange"])
        if config.conf['speech']['autoLanguageSwitching']:
            yield LangChangeCommand(locale)
        if len(speakCharAs) == 1 and synthConfig["useSpellingFunctionality"]:
            if not charMode:
                yield CharacterModeCommand(True)
                charMode = True
        elif charMode:
            yield CharacterModeCommand(False)
            charMode = False
        if uppercase and synthConfig["beepForCapitals"]:
            yield BeepCommand(2000, 50)
        yield speakCharAs
        if uppercase and synth.isSupported(
                "pitch") and synthConfig["capPitchChange"]:
            yield PitchCommand()
        yield EndUtteranceCommand()