home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / speechserver.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  11.7 KB  |  295 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Provides an abtract class for working with speech servers.
  5.  
  6. A speech server (class SpeechServer) provides the ability to tell the
  7. machine to speak.  Each speech server provides a set of known
  8. voices (identified by name) which can be combined with various
  9. attributes to create aural style sheets.'''
  10. __id__ = '$Id: speechserver.py 4467 2009-01-27 16:40:00Z wwalker $'
  11. __version__ = '$Revision: 4467 $'
  12. __date__ = '$Date: 2009-01-27 11:40:00 -0500 (Tue, 27 Jan 2009) $'
  13. __copyright__ = 'Copyright (c) 2005-2008 Sun Microsystems Inc.'
  14. __license__ = 'LGPL'
  15. import logging
  16. import keynames
  17. import settings
  18. import orca
  19. import orca_state
  20. log = logging.getLogger('speech')
  21. import debug
  22. from orca_i18n import _
  23.  
  24. class VoiceFamily(dict):
  25.     '''Holds the family description for a voice.'''
  26.     NAME = 'name'
  27.     GENDER = 'gender'
  28.     LOCALE = 'locale'
  29.     MALE = 'male'
  30.     FEMALE = 'female'
  31.     settings = {
  32.         NAME: None,
  33.         GENDER: None,
  34.         LOCALE: None }
  35.     
  36.     def __init__(self, props):
  37.         '''Create and initialize VoiceFamily.'''
  38.         dict.__init__(self)
  39.         self.update(VoiceFamily.settings)
  40.         if props:
  41.             self.update(props)
  42.         
  43.  
  44.  
  45.  
  46. class SayAllContext:
  47.     PROGRESS = 0
  48.     INTERRUPTED = 1
  49.     COMPLETED = 2
  50.     
  51.     def __init__(self, obj, utterance, startOffset = -1, endOffset = -1):
  52.         """Creates a new SayAllContext that will be passed to the
  53.         SayAll callback handler for progress updates on speech.
  54.         If the object does not have an accessible text specialization,
  55.         then startOffset and endOffset parameters are meaningless.
  56.         If the object does have an accessible text specialization,
  57.         then values >= 0 for startOffset and endOffset indicate
  58.         where in the text the utterance has come from.
  59.  
  60.         Arguments:
  61.         -obj:         the Accessible being spoken
  62.         -utterance:   the actual utterance being spoken
  63.         -startOffset: the start offset of the Accessible's text
  64.         -endOffset:   the end offset of the Accessible's text
  65.         """
  66.         self.obj = obj
  67.         self.utterance = utterance
  68.         self.startOffset = startOffset
  69.         self.currentOffset = startOffset
  70.         self.endOffset = endOffset
  71.  
  72.  
  73.  
  74. class SpeechServer(object):
  75.     '''Provides speech server abstraction.'''
  76.     
  77.     def getFactoryName():
  78.         '''Returns a localized name describing this factory.'''
  79.         pass
  80.  
  81.     getFactoryName = staticmethod(getFactoryName)
  82.     
  83.     def getSpeechServers():
  84.         '''Gets available speech servers as a list.  The caller
  85.         is responsible for calling the shutdown() method of each
  86.         speech server returned.
  87.         '''
  88.         pass
  89.  
  90.     getSpeechServers = staticmethod(getSpeechServers)
  91.     
  92.     def getSpeechServer(info):
  93.         '''Gets a given SpeechServer based upon the info.
  94.         See SpeechServer.getInfo() for more info.
  95.         '''
  96.         pass
  97.  
  98.     getSpeechServer = staticmethod(getSpeechServer)
  99.     
  100.     def shutdownActiveServers():
  101.         '''Cleans up and shuts down this factory.
  102.         '''
  103.         pass
  104.  
  105.     shutdownActiveServers = staticmethod(shutdownActiveServers)
  106.     
  107.     def __init__(self):
  108.         pass
  109.  
  110.     
  111.     def getInfo(self):
  112.         '''Returns [name, id]
  113.         '''
  114.         pass
  115.  
  116.     
  117.     def getVoiceFamilies(self):
  118.         '''Returns a list of VoiceFamily instances representing all
  119.         voice families known by the speech server.'''
  120.         pass
  121.  
  122.     
  123.     def queueText(self, text = '', acss = None):
  124.         '''Adds the text to the queue.
  125.  
  126.         Arguments:
  127.         - text: text to be spoken
  128.         - acss: acss.ACSS instance; if None,
  129.                 the default voice settings will be used.
  130.                 Otherwise, the acss settings will be
  131.                 used to augment/override the default
  132.                 voice settings.
  133.  
  134.         Output is produced by the next call to speak.
  135.         '''
  136.         pass
  137.  
  138.     
  139.     def queueTone(self, pitch = 440, duration = 50):
  140.         '''Adds a tone to the queue.
  141.  
  142.         Output is produced by the next call to speak.
  143.         '''
  144.         pass
  145.  
  146.     
  147.     def queueSilence(self, duration = 50):
  148.         '''Adds silence to the queue.
  149.  
  150.         Output is produced by the next call to speak.
  151.         '''
  152.         pass
  153.  
  154.     
  155.     def speakCharacter(self, character, acss = None):
  156.         '''Speaks a single character immediately.
  157.  
  158.         Arguments:
  159.         - character: text to be spoken
  160.         - acss:      acss.ACSS instance; if None,
  161.                      the default voice settings will be used.
  162.                      Otherwise, the acss settings will be
  163.                      used to augment/override the default
  164.                      voice settings.
  165.         '''
  166.         pass
  167.  
  168.     
  169.     def speakKeyEvent(self, event_string, eventType):
  170.         '''Speaks a key event immediately.
  171.  
  172.         Arguments:
  173.         - event_string: string representing the key event as defined by
  174.                         input_event.KeyboardEvent.
  175.         - eventType:    key event type as one of orca.KeyEventType constants.
  176.  
  177.         '''
  178.         if eventType == orca.KeyEventType.PRINTABLE and event_string.decode('UTF-8').isupper():
  179.             voice = settings.voices[settings.UPPERCASE_VOICE]
  180.         else:
  181.             voice = settings.voices[settings.DEFAULT_VOICE]
  182.         event_string = keynames.getKeyName(event_string)
  183.         if orca_state.activeScript and orca_state.usePronunciationDictionary:
  184.             event_string = orca_state.activeScript.adjustForPronunciation(event_string)
  185.         
  186.         if eventType == orca.KeyEventType.LOCKING_LOCKED:
  187.             event_string += ' ' + _('on')
  188.         elif eventType == orca.KeyEventType.LOCKING_UNLOCKED:
  189.             event_string += ' ' + _('off')
  190.         
  191.         logLine = "SPEECH OUTPUT: '" + event_string + "'"
  192.         debug.println(debug.LEVEL_INFO, logLine)
  193.         log.info(logLine)
  194.         self.speak(event_string, acss = voice)
  195.  
  196.     
  197.     def speakUtterances(self, utteranceList, acss = None, interrupt = True):
  198.         '''Speaks the given list of utterances immediately.
  199.  
  200.         Arguments:
  201.         - utteranceList: list of strings to be spoken
  202.         - acss:      acss.ACSS instance; if None,
  203.                      the default voice settings will be used.
  204.                      Otherwise, the acss settings will be
  205.                      used to augment/override the default
  206.                      voice settings.
  207.         - interrupt: if True, stop any speech currently in progress.
  208.         '''
  209.         pass
  210.  
  211.     
  212.     def speak(self, text = None, acss = None, interrupt = True):
  213.         '''Speaks all queued text immediately.  If text is not None,
  214.         it is added to the queue before speaking.
  215.  
  216.         Arguments:
  217.         - text:      optional text to add to the queue before speaking
  218.         - acss:      acss.ACSS instance; if None,
  219.                      the default voice settings will be used.
  220.                      Otherwise, the acss settings will be
  221.                      used to augment/override the default
  222.                      voice settings.
  223.         - interrupt: if True, stops any speech in progress before
  224.                      speaking the text
  225.         '''
  226.         pass
  227.  
  228.     
  229.     def isSpeaking(self):
  230.         '''"Returns True if the system is currently speaking.'''
  231.         return False
  232.  
  233.     
  234.     def sayAll(self, utteranceIterator, progressCallback):
  235.         '''Iterates through the given utteranceIterator, speaking
  236.         each utterance one at a time.  Subclasses may postpone
  237.         getting a new element until the current element has been
  238.         spoken.
  239.  
  240.         Arguments:
  241.         - utteranceIterator: iterator/generator whose next() function
  242.                              returns a [SayAllContext, acss] tuple
  243.         - progressCallback:  called as speech progress is made - has a
  244.                              signature of (SayAllContext, type), where
  245.                              type is one of PROGRESS, INTERRUPTED, or
  246.                              COMPLETED.
  247.         '''
  248.         for context, acss in utteranceIterator:
  249.             logLine = "SPEECH OUTPUT: '" + context.utterance + "'"
  250.             debug.println(debug.LEVEL_INFO, logLine)
  251.             log.info(logLine)
  252.             self.speak(context.utterance, acss)
  253.         
  254.  
  255.     
  256.     def increaseSpeechRate(self, step = 5):
  257.         '''Increases the speech rate.
  258.         '''
  259.         pass
  260.  
  261.     
  262.     def decreaseSpeechRate(self, step = 5):
  263.         '''Decreases the speech rate.
  264.         '''
  265.         pass
  266.  
  267.     
  268.     def increaseSpeechPitch(self, step = 0.5):
  269.         '''Increases the speech pitch.
  270.         '''
  271.         pass
  272.  
  273.     
  274.     def decreaseSpeechPitch(self, step = 0.5):
  275.         '''Decreases the speech pitch.
  276.         '''
  277.         pass
  278.  
  279.     
  280.     def stop(self):
  281.         '''Stops ongoing speech and flushes the queue.'''
  282.         pass
  283.  
  284.     
  285.     def shutdown(self):
  286.         '''Shuts down the speech engine.'''
  287.         pass
  288.  
  289.     
  290.     def reset(self, text = None, acss = None):
  291.         '''Resets the speech engine.'''
  292.         pass
  293.  
  294.  
  295.