socializer/src/output.py

43 lines
909 B
Python
Raw Normal View History

2016-02-13 17:06:36 -06:00
# *- coding: utf-8 -*-
import logging as original_logging
2016-06-02 17:42:44 -05:00
logger = original_logging.getLogger('core.output')
2016-02-13 17:06:36 -06:00
from accessible_output2 import outputs
import sys
speaker = None
2016-06-02 17:42:44 -05:00
retries = 0
2016-02-13 17:06:36 -06:00
def speak(text, interrupt=0):
2016-06-02 17:42:44 -05:00
global speaker, retries
2016-04-05 12:44:35 -05:00
if not speaker:
setup()
2016-06-02 17:42:44 -05:00
try:
speaker.speak(text, interrupt)
except:
if retries < 5:
retries = retries + 1
speak(text)
# speaker.braille(text)
2016-02-13 17:06:36 -06:00
def setup ():
2016-04-05 12:44:35 -05:00
global speaker
2016-06-02 17:42:44 -05:00
logger.debug("Initializing output subsystem.")
2016-04-05 12:44:35 -05:00
try:
# speaker = speech.Speaker(speech.outputs.Sapi5())
# else:
speaker = outputs.auto.Auto()
except:
2016-06-02 17:42:44 -05:00
logger.exception("Output: Error during initialization.")
def enable_sapi():
speaker = outputs.sapi.SAPI5()
2016-02-13 17:06:36 -06:00
2016-04-05 12:44:35 -05:00
def copy(text):
import win32clipboard
#Copies text to the clipboard.
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text)
win32clipboard.CloseClipboard()