Module speech
[hide private]

Module speech

source code

High-level functions to speak information.

Classes [hide private]
  SpeakTextInfoState
Caches the state of speakTextInfo such as the current controlField stack, current formatfield and indentation.
  SpeechCommand
The base class for objects that can be inserted between string of text for parituclar speech functions that convey things such as indexing or voice parameter changes.
  IndexCommand
Represents an index within some speech.
  CharacterModeCommand
Turns character mode on and off for speech synths.
  LangChangeCommand
A command to switch the language within speech.
  SpeakWithoutPausesBreakCommand
Forces speakWithoutPauses to flush its buffer and therefore break the sentence at this point.
  BreakCommand
Insert a break between words.
  PitchCommand
Change the pitch of the voice.
  VolumeCommand
Change the volume of the voice.
  RateCommand
Change the rate of the voice.
  PhonemeCommand
Insert a specific pronunciation.
Functions [hide private]
 
initialize()
Loads and sets the synth driver configured in nvda.ini.
source code
 
terminate() source code
bool
isBlank(text)
Determine whether text should be reported as blank.
source code
 
processText(locale, text, symbolLevel) source code
int
getLastSpeechIndex()
Gets the last index passed by the synthesizer.
source code
 
cancelSpeech()
Interupts the synthesizer from currently speaking
source code
 
pauseSpeech(switch) source code
 
speakMessage(text, index=None)
Speaks a given message.
source code
 
getCurrentLanguage() source code
 
spellTextInfo(info, useCharacterDescriptions=False)
Spells the text from the given TextInfo, honouring any LangChangeCommand objects it finds if autoLanguageSwitching is enabled.
source code
 
speakSpelling(text, locale=None, useCharacterDescriptions=False) source code
 
getCharDescListFromText(text, locale)
This method prepares a list, which contains character and its description for all characters the text is made up of, by checking the presence of character descriptions in characterDescriptions.dic of that locale for all possible combination of consecutive characters in the text.
source code
 
_speakSpellingGen(text, locale, useCharacterDescriptions) source code
 
speakObjectProperties(obj, reason=controlTypes.REASON_QUERY, index=None, **allowedProperties) source code
 
_speakPlaceholderIfEmpty(info, obj, reason)
attempt to speak placeholder attribute if the textInfo 'info' is empty
source code
 
speakObject(obj, reason=controlTypes.REASON_QUERY, index=None) source code
 
speakText(text, index=None, reason=controlTypes.REASON_MESSAGE, symbolLevel=None)
Speaks some text.
source code
(basestring, basestring)
splitTextIndentation(text)
Splits indentation from the rest of the text.
source code
unicode
getIndentationSpeech(indentation, formatConfig)
Retrieves the phrase to be spoken for a given string of indentation.
source code
 
speak(speechSequence, symbolLevel=None)
Speaks a sequence of text and speech commands
source code
 
speakSelectionMessage(message, text) source code
 
speakSelectionChange(oldInfo, newInfo, speakSelected=True, speakUnselected=True, generalize=False)
Speaks a change in selection, either selected or unselected text.
source code
 
_suppressSpeakTypedCharacters(number)
Suppress speaking of typed characters.
source code
 
speakTypedCharacters(ch) source code
 
_speakTextInfo_addMath(speechSequence, info, field) source code
 
speakTextInfo(info, useCache=True, formatConfig=None, unit=None, reason=controlTypes.REASON_QUERY, index=None, onlyInitialFields=False, suppressBlanks=False) source code
 
getSpeechTextForProperties(reason=controlTypes.REASON_QUERY, **propertyValues) source code
 
getControlFieldSpeech(attrs, ancestorAttrs, fieldType, formatConfig=None, extraDetail=False, reason=None) source code
 
getFormatFieldSpeech(attrs, attrsCache=None, formatConfig=None, reason=None, unit=None, extraDetail=False, initialFormat=False, separator=CHUNK_SEPARATOR) source code
 
getTableInfoSpeech(tableInfo, oldTableInfo, extraDetail=False) source code
 
speakWithoutPauses(speechSequence, detectBreaks=True)
Speaks the speech sequences given over multiple calls, only sending to the synth at acceptable phrase or sentence boundaries, or when given None for the speech sequence.
source code
Variables [hide private]
  speechMode_off = 0
  speechMode_beeps = 1
  speechMode_talk = 2
  speechMode = 2
How speech should be handled; one of speechMode_off, speechMode_beeps or speechMode_talk.
  speechMode_beeps_ms = 15
  beenCanceled = True
  isPaused = False
  curWordChars = []
  LANGS_WITH_CONJUNCT_CHARS = {'hi', 'as', 'bn', 'gu', 'kn', 'ko...
  CHUNK_SEPARATOR = " "
The string used to separate distinct chunks of text when multiple chunks should be spoken without pauses.
  oldTreeLevel = None
hash(x)
  oldTableID = None
hash(x)
  oldRowNumber = None
hash(x)
  oldRowSpan = None
hash(x)
  oldColumnNumber = None
hash(x)
  oldColumnSpan = None
hash(x)
  BLANK_CHUNK_CHARS = frozenset((" ", "\n", "\r", "\0", u"\xa0"))
If a chunk of text contains only these characters, it will be considered blank.
  RE_CONVERT_WHITESPACE = re.compile("[\0\r\n]")
  _speakSpellingGenerator = None
hash(x)
  RE_INDENTATION_SPLIT = re.compile(r"^([^\S\r\n\f\v]*)(.*)$", r...
  RE_INDENTATION_CONVERT = re.compile(r"(?P<char>\s)(?P=char)*",...
  IDT_BASE_FREQUENCY = 220
  IDT_TONE_DURATION = 80
  IDT_MAX_SPACES = 72
  _suppressSpeakTypedCharactersNumber = 0
The number of typed characters for which to suppress speech.
  _suppressSpeakTypedCharactersTime = None
The time at which suppressed typed characters were sent.
  PROTECTED_CHAR = "*"
The character to use when masking characters in protected fields.
  FIRST_NONCONTROL_CHAR = u" "
The first character which is not a Unicode control character.
  re_last_pause = re.compile(ur"^(.*(?<=[^\s.!?])[.!?][\"'”’)]?(...
Function Details [hide private]

isBlank(text)

source code 

Determine whether text should be reported as blank.

Parameters:
  • text (str) - The text in question.
Returns: bool
True if the text is blank, False if not.

getLastSpeechIndex()

source code 

Gets the last index passed by the synthesizer. Indexing is used so that its possible to find out when a certain peace of text has been spoken yet. Usually the character position of the text is passed to speak functions as the index.

Returns: int
the last index encountered

speakMessage(text, index=None)

source code 

Speaks a given message.

Parameters:
  • text (string) - the message to speak
  • index (int) - the index to mark this current text with, its best to use the character position of the text if you know it

getCharDescListFromText(text, locale)

source code 

This method prepares a list, which contains character and its description for all characters the text is made up of, by checking the presence of character descriptions in characterDescriptions.dic of that locale for all possible combination of consecutive characters in the text. This is done to take care of conjunct characters present in several languages such as Hindi, Urdu, etc.

_speakPlaceholderIfEmpty(info, obj, reason)

source code 

attempt to speak placeholder attribute if the textInfo 'info' is empty

Returns:
True if info was considered empty, and we attempted to speak the placeholder value. False if info was not considered empty.

speakText(text, index=None, reason=controlTypes.REASON_MESSAGE, symbolLevel=None)

source code 

Speaks some text.

Parameters:
  • text (str) - The text to speak.
  • index (int) - The index to mark this text with, which can be used later to determine whether this piece of text has been spoken.
  • reason - The reason for this speech; one of the controlTypes.REASON_* constants.
  • symbolLevel - The symbol verbosity level; None (default) to use the user's configuration.

splitTextIndentation(text)

source code 

Splits indentation from the rest of the text.

Parameters:
  • text (basestring) - The text to split.
Returns: (basestring, basestring)
Tuple of indentation and content.

getIndentationSpeech(indentation, formatConfig)

source code 

Retrieves the phrase to be spoken for a given string of indentation.

Parameters:
  • indentation (unicode) - The string of indentation.
  • formatConfig (dict) - The configuration to use.
Returns: unicode
The phrase to be spoken.

speak(speechSequence, symbolLevel=None)

source code 

Speaks a sequence of text and speech commands

Parameters:
  • speechSequence - the sequence of text and SpeechCommand objects to speak
  • symbolLevel - The symbol verbosity level; None (default) to use the user's configuration.

speakSelectionChange(oldInfo, newInfo, speakSelected=True, speakUnselected=True, generalize=False)

source code 

Speaks a change in selection, either selected or unselected text.

Parameters:
  • oldInfo (textInfos.TextInfo) - a TextInfo instance representing what the selection was before
  • newInfo (textInfos.TextInfo) - a TextInfo instance representing what the selection is now
  • generalize (boolean) - if True, then this function knows that the text may have changed between the creation of the oldInfo and newInfo objects, meaning that changes need to be spoken more generally, rather than speaking the specific text, as the bounds may be all wrong.

_suppressSpeakTypedCharacters(number)

source code 

Suppress speaking of typed characters. This should be used when sending a string of characters to the system and those characters should not be spoken individually as if the user were typing them.

Parameters:
  • number (int) - The number of characters to suppress.

Variables Details [hide private]

LANGS_WITH_CONJUNCT_CHARS

Value:
{'hi', 'as', 'bn', 'gu', 'kn', 'kok', 'ml', 'mni', 'mr', 'pa', 'te', '\
ur', 'ta'}

RE_INDENTATION_SPLIT

Value:
re.compile(r"^([^\S\r\n\f\v]*)(.*)$", re.UNICODE | re.DOTALL)

RE_INDENTATION_CONVERT

Value:
re.compile(r"(?P<char>\s)(?P=char)*", re.UNICODE)

FIRST_NONCONTROL_CHAR

The first character which is not a Unicode control character. This is used to test whether a character should be spoken as a typed character; i.e. it should have a visual or spatial representation.

Value:
u" "

re_last_pause

Value:
re.compile(ur"^(.*(?<=[^\s.!?])[.!?][\"'”’)]?(?:\s+|$))(.*$)", re.DOTA\
LL | re.UNICODE)