2014-10-27 16:29:04 -06:00
|
|
|
from base import Output, OutputError
|
|
|
|
import atexit
|
2015-05-01 02:05:25 -04:00
|
|
|
import application
|
2014-10-27 16:29:04 -06:00
|
|
|
class SpeechDispatcher(Output):
|
|
|
|
"""Supports speech dispatcher on Linux.
|
2015-05-01 02:05:25 -04:00
|
|
|
Note that this module will use the configuration of speech dispatcher, the user will need to configure the voice, language, punctuation and rate before using this module.
|
2014-10-27 16:29:04 -06:00
|
|
|
"""
|
|
|
|
name = 'SpeechDispatcher'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(SpeechDispatcher, self).__init__(*args, **kwargs)
|
|
|
|
try:
|
|
|
|
import speechd
|
2015-05-01 02:05:25 -04:00
|
|
|
self.spd = speechd.SSIPClient(application.name)
|
2014-10-27 16:29:04 -06:00
|
|
|
except ImportError:
|
|
|
|
raise OutputError
|
|
|
|
atexit.register(self.on_exit_event)
|
|
|
|
|
|
|
|
def speak(self, text, interupt=False):
|
|
|
|
if interupt == True:
|
|
|
|
self.spd.cancel()
|
|
|
|
self.spd.speak(text)
|
|
|
|
|
|
|
|
def is_active(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def on_exit_event(self):
|
|
|
|
self.spd.close()
|
|
|
|
del self.spd
|