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

114 lines
6.9 KiB
Python
Raw Normal View History

2016-07-13 05:15:19 -04:00
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
2016-08-23 18:41:16 -04:00
2016-07-13 05:15:19 -04:00
class outputManager():
def __init__(self):
pass
def initialize(self, environment):
environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'speech', 'driver'), 'speechDriver')
environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'), 'soundDriver')
def shutdown(self, environment):
if environment['runtime']['soundDriver']:
environment['runtime']['soundDriver'].shutdown(environment)
2016-09-21 10:56:17 -04:00
del environment['runtime']['soundDriver']
if environment['runtime']['speechDriver']:
2016-09-21 10:56:17 -04:00
environment['runtime']['speechDriver'].shutdown(environment)
del environment['runtime']['speechDriver']
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):
2016-09-02 12:08:44 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"soundIcon found" ,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'):
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"Speech disabled in outputManager.speakText",debug.debugLevel.INFO)
return
2016-07-26 10:19:23 -04:00
if environment['runtime']['speechDriver'] == None:
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"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:
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"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:
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"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:
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"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:
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"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:
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"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:
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"\"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-09-17 14:08:56 -04:00
soundIcon = soundIcon.upper()
2016-07-14 17:25:33 -04:00
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'sound', 'enabled'):
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"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:
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"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:
2016-09-17 14:08:56 -04:00
environment['runtime']['debug'].writeDebugOut(environment,"\"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