def getShortDesc(s): lang = languageHandler.getLanguage()[:2] if len(s) == 1 and ord(s) < 128 and lang != 'ja': return characterProcessing.processSpeechSymbol(lang, s) s2 = characterProcessing.processSpeechSymbol('ja', s) if s != s2: return s2 return characterProcessing.getCharacterReading('ja', s.lower())
def getCandidateCharDesc(c, a, forBraille=False): d = '' if forBraille and (isLatinCharacter(c) or isZenkakuHiragana(c) or isZenkakuKatakana(c) or isFullShapeNumber(c) or isHalfShapeNumber(c) or c == u'.'): d = c elif a.half or isFullShapeAlphabet(c) or isFullShapeNumber( c) or isFullShapeSymbol(c): d = getShortDesc(c) log.debug(u"shortdesc (%s) %s" % (c, d)) elif a.hira or a.kata: d = replaceSpecialKanaCharacter(c) log.debug(u"kana (%s) %s" % (c, d)) else: d = getLongDesc(c) if d != c: log.debug(u"longdesc (%s) %s" % (c, d)) else: d2 = characterProcessing.processSpeechSymbol('ja', c) if d != d2: log.debug(u"sym (%s) %s" % (c, d2)) d = d2 elif (0xd800 <= ord(c[0]) <= 0xdbff) and len(c) == 2: uc = (ord(c[0]) - 0xd800) * 0x800 + (ord(c[1]) - 0xdc00) d = code2hex(uc) log.debug(u"sp (%s) %s" % (c, d)) else: d = code2hex(ord(c[0])) log.debug(u"code (%s) %s" % (c, d)) if len(d) > 1: return ' ' + d + ' ' return d
def script_showCaretSymbol(self, gesture): obj = api.getFocusObject() treeInterceptor = obj.treeInterceptor if isinstance(treeInterceptor, treeInterceptorHandler.DocumentTreeInterceptor ) and not treeInterceptor.passThrough: obj = treeInterceptor try: info = obj.makeTextInfo(textInfos.POSITION_CARET) except: info = obj.makeTextInfo(textInfos.POSITION_FIRST) info.expand(textInfos.UNIT_CHARACTER) curLanguage = self._getCurrentLanguageForTextInfo(info) text = info.text expandedSymbol = characterProcessing.processSpeechSymbol( curLanguage, text) if expandedSymbol == text: # Translators: Reported when there is no replacement for the symbol at the position of the caret. ui.message(_("No symbol replacement")) return # Translators: Character and its replacement used from the "Review current Symbol" command. Example: "Character: ? Replacement: question" message = _("Character: {}\nReplacement: {}").format( text, expandedSymbol) languageDescription = languageHandler.getLanguageDescription( curLanguage) # Translators: title for expanded symbol dialog. Example: "Expanded symbol (English)" title = _("Symbol at the caret position ({})").format( languageDescription) ui.browseableMessage(message, title)
def script_showReviewCursorSymbol(self, gesture): info = api.getReviewPosition().copy() info.expand(textInfos.UNIT_CHARACTER) curLanguage = self._getCurrentLanguageForTextInfo(info) text = info.text expandedSymbol = characterProcessing.processSpeechSymbol( curLanguage, text) if expandedSymbol == text: # Translators: Reported when there is no replacement for the symbol at the position of the review cursor. ui.message(_("No symbol replacement")) return # Translators: Character and its replacement used from the "Review current Symbol" command. Example: "Character: ? Replacement: question" message = _("Character: {}\nReplacement: {}").format( text, expandedSymbol) languageDescription = languageHandler.getLanguageDescription( curLanguage) # Translators: title for expanded symbol dialog. Example: "Expanded symbol (English)" title = _("Symbol at the review cursor position ({})").format( languageDescription) ui.browseableMessage(message, title)
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()