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

114 lines
6.2 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):
self.env = environment
self.env['runtime']['settingsManager'].loadDriver(\
self.env['runtime']['settingsManager'].getSetting('speech', 'driver'), 'speechDriver')
self.env['runtime']['settingsManager'].loadDriver(\
self.env['runtime']['settingsManager'].getSetting('sound', 'driver'), 'soundDriver')
def shutdown(self):
self.env['runtime']['settingsManager'].shutdownDriver('soundDriver')
self.env['runtime']['settingsManager'].shutdownDriver('speechDriver')
2016-09-22 16:42:14 -04:00
def presentText(self, text, interrupt=True, soundIcon = '', ignorePunctuation=False):
self.env['runtime']['debug'].writeDebugOut("presentText:\nsoundIcon:'"+soundIcon+"'\nText:\n" + text ,debug.debugLevel.INFO)
if self.playSoundIcon(soundIcon, interrupt):
self.env['runtime']['debug'].writeDebugOut("soundIcon found" ,debug.debugLevel.INFO)
2016-08-02 20:26:44 -04:00
return
self.speakText(text, interrupt)
self.brailleText(text, interrupt)
2016-07-14 17:00:02 -04:00
2016-09-22 16:42:14 -04:00
def speakText(self, text, interrupt=True, ignorePunctuation=False):
if not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'enabled'):
self.env['runtime']['debug'].writeDebugOut("Speech disabled in outputManager.speakText",debug.debugLevel.INFO)
return
if self.env['runtime']['speechDriver'] == None:
self.env['runtime']['debug'].writeDebugOut("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:
self.interruptOutput()
try:
self.env['runtime']['speechDriver'].setLanguage(self.env['runtime']['settingsManager'].getSetting('speech', 'language'))
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("setting speech language in outputManager.speakText",debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
try:
self.env['runtime']['speechDriver'].setVoice(self.env['runtime']['settingsManager'].getSetting('speech', 'voice'))
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("Error while setting speech voice in outputManager.speakText",debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
try:
self.env['runtime']['speechDriver'].setPitch(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'pitch'))
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("setting speech pitch in outputManager.speakText",debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
try:
self.env['runtime']['speechDriver'].setRate(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'rate'))
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("setting speech rate in outputManager.speakText",debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
try:
self.env['runtime']['speechDriver'].setModule(self.env['runtime']['settingsManager'].getSetting('speech', 'module'))
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("setting speech module in outputManager.speakText",debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
try:
self.env['runtime']['speechDriver'].setVolume(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'volume'))
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("setting speech volume in outputManager.speakText ",debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
try:
2016-09-22 16:42:14 -04:00
text = self.env['runtime']['punctuationManager'].proceedPunctuation(text,ignorePunctuation)
self.env['runtime']['speechDriver'].speak(text)
except Exception as e:
2016-09-22 16:42:14 -04:00
print(e)
self.env['runtime']['debug'].writeDebugOut("\"speak\" in outputManager.speakText ",debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
2016-07-14 17:00:02 -04:00
def brailleText(self, text, interrupt=True):
if not self.env['runtime']['settingsManager'].getSettingAsBool('braille', 'enabled'):
2016-07-26 10:19:23 -04:00
return
if self.env['runtime']['brailleDriver'] == None:
2016-07-26 10:19:23 -04:00
return
print('braille:'+text)
2016-07-26 17:39:22 -04:00
def interruptOutput(self):
self.env['runtime']['speechDriver'].cancel()
self.env['runtime']['soundDriver'].cancel()
def playSoundIcon(self, soundIcon = '', interrupt=True):
2016-08-10 09:30:43 -04:00
if soundIcon == '':
2016-08-02 20:26:44 -04:00
return False
2016-09-17 14:08:56 -04:00
soundIcon = soundIcon.upper()
if not self.env['runtime']['settingsManager'].getSettingAsBool('sound', 'enabled'):
self.env['runtime']['debug'].writeDebugOut("Sound disabled in outputManager.speakText",debug.debugLevel.INFO)
2016-08-02 20:26:44 -04:00
return False
if self.env['runtime']['soundDriver'] == None:
self.env['runtime']['debug'].writeDebugOut("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:
self.env['runtime']['soundDriver'].setVolume(self.env['runtime']['settingsManager'].getSettingAsFloat('sound', 'volume'))
self.env['runtime']['soundDriver'].playSoundFile(self.env['soundIcons'][soundIcon], interrupt)
2016-08-02 20:26:44 -04:00
return True
except Exception as e:
self.env['runtime']['debug'].writeDebugOut("\"playSoundIcon\" in outputManager.speakText ",debug.debugLevel.ERROR)
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
2016-08-02 20:26:44 -04:00
return False