def _speak(text, acss, interrupt): """Speaks the individual string using the given ACSS.""" if settings.speakMultiCaseStringsAsWords: text = _processMultiCaseString(text) if orca_state.activeScript and orca_state.usePronunciationDictionary: text = orca_state.activeScript.utilities.adjustForPronunciation(text) if settings.speakMultiCaseStringsAsWords: text = _processMultiCaseString(text) logLine = "SPEECH OUTPUT: '" + text + "'" extraDebug = "" if acss in settings.voices.values(): for key in settings.voices: if acss == settings.voices[key]: if key != settings.DEFAULT_VOICE: extraDebug = " voice=%s" % key break try: extraDebug = extraDebug.encode("UTF-8") except UnicodeDecodeError: pass debug.println(debug.LEVEL_INFO, logLine + extraDebug) log.info(logLine + extraDebug) if _speechserver: voice = ACSS(settings.voices.get(settings.DEFAULT_VOICE)) try: voice.update(acss) except: pass _speechserver.speak(text, __resolveACSS(voice), interrupt)
def testNoSettingsInit(): init() speak("testing") speak("this is higher", ACSS({'average-pitch': 7})) speak("this is slower", ACSS({'rate': 3})) speak("this is faster", ACSS({'rate': 80})) speak("this is quiet", ACSS({'gain': 2})) speak("this is loud", ACSS({'gain': 10})) speak("this is normal")
def test(): import speechserver factories = getSpeechServerFactories() for factory in factories: print factory.__name__ servers = factory.SpeechServer.getSpeechServers() for server in servers: try: print " ", server.getInfo() for family in server.getVoiceFamilies(): name = family[speechserver.VoiceFamily.NAME] print " ", name acss = ACSS({ACSS.FAMILY: family}) server.speak(name, acss) server.speak("testing") server.shutdown() except: debug.printException(debug.LEVEL_OFF) pass
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)
# silenceSpeech = False # Settings that apply to the particular speech engine to # use as well details on the default voices to use. # speechFactoryModules = ["espeechfactory","gnomespeechfactory","speechdispatcherfactory"] speechServerFactory = "gnomespeechfactory" speechServerInfo = None # None means let the factory decide. DEFAULT_VOICE = "default" UPPERCASE_VOICE = "uppercase" HYPERLINK_VOICE = "hyperlink" voices = { DEFAULT_VOICE : ACSS({}), UPPERCASE_VOICE : ACSS({ACSS.AVERAGE_PITCH : 5.6}), HYPERLINK_VOICE : ACSS({}) } # If True, enable speaking of speech indentation and justification. # enableSpeechIndentation = False # If True, enable braille. # enableBraille = True # If True, enable the grouping of children on the braille display. # This is for things like displaying all items of a menu, tab list, # menu bar, etc., on a single line of the braille display.