enet-client-server/examples/chat app/client/output.py

32 lines
776 B
Python
Raw Normal View History

2020-05-12 20:03:14 -05:00
# *- coding: utf-8 -*-
""" Simple (really simple) module to provide text to speech output in a chat window."""
import logging as original_logging
logger = original_logging.getLogger('core.output')
from accessible_output2 import outputs
import sys
speaker = None
retries = 0
def speak(text, interrupt=0):
2022-01-14 11:47:24 -06:00
global speaker, retries
if not speaker:
setup()
try:
speaker.speak(text, interrupt)
except:
if retries < 5:
retries = retries + 1
speak(text)
2020-05-12 20:03:14 -05:00
def setup ():
2022-01-14 11:47:24 -06:00
global speaker
logger.debug("Initializing output subsystem.")
try:
speaker = outputs.auto.Auto()
except:
logger.exception("Output: Error during initialization.")
2020-05-12 20:03:14 -05:00
def enable_sapi():
2022-01-14 11:47:24 -06:00
speaker = outputs.sapi.SAPI5()