def reset(self, text=None, acss=None): """Resets the speech engine.""" # We might get into a vicious loop of resetting speech, so # we will abort if we see this happening. # if (time.time() - self.__lastResetTime) < 20: debug.println(debug.LEVEL_SEVERE, "Something looks wrong with speech. Aborting.") debug.printStack(debug.LEVEL_ALL) os._exit(50) else: self.__lastResetTime = time.time() speakers = self.__speakers self.shutdown() servers = bonobo.activation.query( "repo_ids.has('IDL:GNOME/Speech/SynthesisDriver:0.3')") for server in servers: if server.iid == self.__iid: try: self.__driver = self.__activateDriver(self.__iid) self.__speakers = {} for name in speakers.keys(): self.__getSpeaker(speakers[name]) if text: self.speak(text, acss) break except: debug.printException(debug.LEVEL_SEVERE) self.__driver = None pass
def getValueForKey(prefsDict, key): need2repr = ['brailleEOLIndicator', 'brailleContractionTable', 'brailleRequiredStateString', 'enabledBrailledTextAttributes', 'enabledSpokenTextAttributes', 'speechRequiredStateString', 'speechServerFactory', 'presentDateFormat', 'presentTimeFormat'] value = None if key in prefsDict: if type(prefsDict[key]) is str: if key in need2repr: value = "\'%s\'" % prefsDict[key] elif key == 'voices': key = getVoiceKey(key) value = prefsDict[key] else: try: value = getattr(settings, prefsDict[key]) except: debug.println(debug.LEVEL_SEVERE, "Something went wront with key: " % key) debug.printStack(debug.LEVEL_FINEST) else: value = prefsDict[key] return value
def _processInputEvent(self, event): """Processes the given input event based on the keybinding from the currently-active script. Arguments: - event: an instance of BrailleEvent or a KeyboardEvent """ if not orca_state.activeScript: return if isinstance(event, input_event.KeyboardEvent): function = orca_state.activeScript.processKeyboardEvent data = "'%s' (%d)" % (event.event_string, event.hw_code) elif isinstance(event, input_event.BrailleEvent): function = orca_state.activeScript.processBrailleEvent data = "'%s'" % repr(event.event) else: return eType = str(event.type).upper() debug.println(debug.eventDebugLevel, "\nvvvvv PROCESS %s %s vvvvv" % (eType, data)) try: function(event) except: debug.printException(debug.LEVEL_WARNING) debug.printStack(debug.LEVEL_WARNING) debug.println(debug.eventDebugLevel, "^^^^^ PROCESS %s %s ^^^^^\n" % (eType, data))
def _processBrailleEvent(self, brailleEvent): """Called whenever a cursor key is pressed on the Braille display. Arguments: - brailleEvent: an instance of input_event.BrailleEvent """ if orca_state.activeScript: try: orca_state.activeScript.processBrailleEvent(brailleEvent) except: debug.printException(debug.LEVEL_WARNING) debug.printStack(debug.LEVEL_WARNING)
def _processKeyboardEvent(self, keyboardEvent): """Processes the given keyboard event based on the keybinding from the currently active script. Arguments: - keyboardEvent: an instance of input_event.KeyboardEvent """ if orca_state.activeScript: try: orca_state.activeScript.processKeyboardEvent(keyboardEvent) except: debug.printException(debug.LEVEL_WARNING) debug.printStack(debug.LEVEL_WARNING)
def shutdownOnSignal(signum, frame): global exitCount debug.println(debug.LEVEL_ALL, "Shutting down and exiting due to signal = %d" \ % signum) debug.println(debug.LEVEL_ALL, "Current stack is:") debug.printStack(debug.LEVEL_ALL) # Well...we'll try to exit nicely, but if we keep getting called, # something bad is happening, so just quit. # if exitCount: abort(signum) else: exitCount += 1 # Try to do a graceful shutdown if we can. # if settings.timeoutCallback and (settings.timeoutTime > 0): signal.signal(signal.SIGALRM, settings.timeoutCallback) signal.alarm(settings.timeoutTime) try: if _initialized: shutdown() else: # We always want to try to shutdown speech since the # speech servers are very persistent about living. # speech.shutdown() shutdown() cleanExit = True except: cleanExit = False if settings.timeoutCallback and (settings.timeoutTime > 0): signal.alarm(0) if not cleanExit: abort(signum)
def timeout(signum=None, frame=None): debug.println(debug.LEVEL_SEVERE, "TIMEOUT: something has hung. Aborting.") debug.printStack(debug.LEVEL_ALL) abort(50)
def speak(content, acss=None, interrupt=True): """Speaks the given content. The content can be either a simple string or an array of arrays of objects returned by a speech generator.""" if settings.silenceSpeech: return validTypes = (basestring, list, sound.Sound, speech_generator.Pause, speech_generator.LineBreak, ACSS) error = "bad content sent to speech.speak: '%s'" if not isinstance(content, validTypes): debug.printStack(debug.LEVEL_WARNING) debug.println(debug.LEVEL_WARNING, error % content) return # We will not interrupt a key echo in progress. # if orca_state.lastKeyEchoTime: interrupt = interrupt \ and ((time.time() - orca_state.lastKeyEchoTime) > 0.5) if isinstance(content, basestring): _speak(content, acss, interrupt) elif isinstance(content, sound.Sound): content.play() if not isinstance(content, list): return toSpeak = [] activeVoice = ACSS(acss) for element in content: if not isinstance(element, validTypes): debug.println(debug.LEVEL_WARNING, error % element) elif isinstance(element, list): speak(element, acss, interrupt) elif isinstance(element, basestring): if len(element): toSpeak.append(element) elif toSpeak: newVoice = ACSS(acss) newItemsToSpeak = [] if isinstance(element, speech_generator.Pause): if not toSpeak[-1].endswith('.'): toSpeak[-1] += '.' if not settings.enablePauseBreaks: continue elif isinstance(element, ACSS): newVoice.update(element) if newVoice == activeVoice: continue newItemsToSpeak.append(toSpeak.pop()) if toSpeak: try: toSpeak = map(lambda x: x.decode("UTF-8"), toSpeak) except UnicodeEncodeError: pass string = " ".join(toSpeak) _speak(string, activeVoice, interrupt) activeVoice = newVoice toSpeak = newItemsToSpeak if isinstance(element, sound.Sound): element.play() if toSpeak: try: toSpeak = map(lambda x: x.decode("UTF-8"), toSpeak) except UnicodeEncodeError: pass string = " ".join(toSpeak) _speak(string, activeVoice, interrupt)
def preReadc(force,path,depth = 0,retries = 0): printStack(1) print "\t!!!\tUsing deprecated function\t!!!" return preRead(force,'c',path,depth,retries)