fenrir/src/fenrir-package/core/outputManager.py

94 lines
6.1 KiB
Python
Raw Normal View History

2016-07-13 05:15:19 -04:00
#!/bin/python
from utils import debug
2016-08-23 18:41:16 -04:00
2016-07-13 05:15:19 -04:00
class outputManager():
def __init__(self):
pass
2016-08-10 09:30:43 -04:00
def presentText(self, environment, text, interrupt=True, soundIcon = ''):
environment['runtime']['debug'].writeDebugOut(environment,"presentText:\nsoundIcon:'"+soundIcon+"'\nText:\n" + text ,debug.debugLevel.INFO)
2016-08-10 09:30:43 -04:00
if self.playSoundIcon(environment, soundIcon, interrupt):
environment['runtime']['debug'].writeDebugOut(environment,"presentText:\n" + text ,debug.debugLevel.INFO)
2016-08-02 20:26:44 -04:00
return
2016-07-26 10:19:23 -04:00
self.speakText(environment, text, interrupt)
self.brailleText(environment, text, interrupt)
2016-07-14 17:00:02 -04:00
2016-07-26 10:19:23 -04:00
def speakText(self, environment, text, interrupt=True):
2016-07-14 17:00:02 -04:00
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'speech', 'enabled'):
environment['runtime']['debug'].writeDebugOut(environment,"INFO speech disabled in outputManager.speakText",debug.debugLevel.INFO)
return
2016-07-26 10:19:23 -04:00
if environment['runtime']['speechDriver'] == None:
environment['runtime']['debug'].writeDebugOut(environment,"Error no speechDriver in outputManager.speakText",debug.debugLevel.ERROR)
2016-07-14 17:00:02 -04:00
return
2016-07-26 10:19:23 -04:00
if interrupt:
2016-07-14 17:00:02 -04:00
self.interruptOutput(environment)
try:
environment['runtime']['speechDriver'].setLanguage(environment['runtime']['settingsManager'].getSetting(environment, 'speech', 'language'))
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,"Error while setting speech language in outputManager.speakText",debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
try:
environment['runtime']['speechDriver'].setVoice(environment['runtime']['settingsManager'].getSetting(environment, 'speech', 'voice'))
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,"Error while setting speech voice in outputManager.speakText",debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
try:
environment['runtime']['speechDriver'].setPitch(environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'speech', 'pitch'))
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,"Error while setting speech pitch in outputManager.speakText",debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
try:
environment['runtime']['speechDriver'].setRate(environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'speech', 'rate'))
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,"Error while setting speech rate in outputManager.speakText",debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
try:
environment['runtime']['speechDriver'].setModule(environment['runtime']['settingsManager'].getSetting(environment, 'speech', 'module'))
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,"Error while setting speech module in outputManager.speakText",debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
try:
environment['runtime']['speechDriver'].setVolume(environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'speech', 'volume'))
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,"Error while setting speech volume in outputManager.speakText ",debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
try:
environment['runtime']['speechDriver'].speak(text)
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,"Error while \"speak\" in outputManager.speakText ",debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
2016-07-14 17:00:02 -04:00
def brailleText(self, environment, text, interrupt=True):
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'braille', 'enabled'):
2016-07-26 10:19:23 -04:00
return
2016-08-02 20:26:44 -04:00
if environment['runtime']['brailleDriver'] == None:
2016-07-26 10:19:23 -04:00
return
print('braille:'+text)
2016-07-14 17:00:02 -04:00
def interruptOutput(self, environment):
environment['runtime']['speechDriver'].cancel()
2016-07-26 10:19:23 -04:00
environment['runtime']['soundDriver'].cancel()
2016-07-26 17:39:22 -04:00
2016-08-10 09:30:43 -04:00
def playSoundIcon(self, environment, soundIcon = '', interrupt=True):
if soundIcon == '':
2016-08-02 20:26:44 -04:00
return False
2016-07-14 17:25:33 -04:00
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'sound', 'enabled'):
environment['runtime']['debug'].writeDebugOut(environment,"INFO sound disabled in outputManager.speakText",debug.debugLevel.INFO)
2016-08-02 20:26:44 -04:00
return False
2016-07-26 10:19:23 -04:00
if environment['runtime']['soundDriver'] == None:
environment['runtime']['debug'].writeDebugOut(environment,"Error no speechDriver in outputManager.speakText",debug.debugLevel.ERROR)
2016-08-02 20:26:44 -04:00
return False
2016-07-26 09:59:27 -04:00
try:
environment['runtime']['soundDriver'].setVolume(environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'sound', 'volume'))
2016-08-10 09:30:43 -04:00
environment['runtime']['soundDriver'].playSoundFile(environment['soundIcons'][soundIcon], interrupt)
2016-08-02 20:26:44 -04:00
return True
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,"Error while \"playSoundIcon\" in outputManager.speakText ",debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
2016-08-02 20:26:44 -04:00
return False