2016-07-13 05:15:19 -04:00
|
|
|
#!/bin/python
|
2016-09-19 16:15:58 -04:00
|
|
|
# -*- 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
|
2016-09-02 15:37:36 -04:00
|
|
|
def initialize(self, environment):
|
2016-09-21 17:17:54 -04:00
|
|
|
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')
|
2016-09-16 19:04:03 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def shutdown(self):
|
|
|
|
self.env['runtime']['settingsManager'].shutdownDriver('soundDriver')
|
|
|
|
self.env['runtime']['settingsManager'].shutdownDriver('speechDriver')
|
2016-09-16 19:04:03 -04:00
|
|
|
|
2016-09-22 16:42:14 -04:00
|
|
|
def presentText(self, text, interrupt=True, soundIcon = '', ignorePunctuation=False):
|
2016-09-21 17:17:54 -04:00
|
|
|
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
|
2016-09-21 17:17:54 -04:00
|
|
|
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):
|
2016-09-21 17:17:54 -04:00
|
|
|
if not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'enabled'):
|
|
|
|
self.env['runtime']['debug'].writeDebugOut("Speech disabled in outputManager.speakText",debug.debugLevel.INFO)
|
2016-08-21 17:55:56 -04:00
|
|
|
return
|
2016-09-21 17:17:54 -04:00
|
|
|
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:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.interruptOutput()
|
2016-08-21 17:55:56 -04:00
|
|
|
try:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['speechDriver'].setLanguage(self.env['runtime']['settingsManager'].getSetting('speech', 'language'))
|
2016-08-21 17:55:56 -04:00
|
|
|
except Exception as e:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['debug'].writeDebugOut("setting speech language in outputManager.speakText",debug.debugLevel.ERROR)
|
|
|
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
2016-08-21 17:55:56 -04:00
|
|
|
|
|
|
|
try:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['speechDriver'].setVoice(self.env['runtime']['settingsManager'].getSetting('speech', 'voice'))
|
2016-08-21 17:55:56 -04:00
|
|
|
except Exception as e:
|
2016-09-21 17:17:54 -04:00
|
|
|
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)
|
2016-08-21 17:55:56 -04:00
|
|
|
|
|
|
|
try:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['speechDriver'].setPitch(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'pitch'))
|
2016-08-21 17:55:56 -04:00
|
|
|
except Exception as e:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['debug'].writeDebugOut("setting speech pitch in outputManager.speakText",debug.debugLevel.ERROR)
|
|
|
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
2016-08-21 17:55:56 -04:00
|
|
|
|
|
|
|
try:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['speechDriver'].setRate(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'rate'))
|
2016-08-21 17:55:56 -04:00
|
|
|
except Exception as e:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['debug'].writeDebugOut("setting speech rate in outputManager.speakText",debug.debugLevel.ERROR)
|
|
|
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
2016-08-21 17:55:56 -04:00
|
|
|
|
|
|
|
try:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['speechDriver'].setModule(self.env['runtime']['settingsManager'].getSetting('speech', 'module'))
|
2016-08-21 17:55:56 -04:00
|
|
|
except Exception as e:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['debug'].writeDebugOut("setting speech module in outputManager.speakText",debug.debugLevel.ERROR)
|
|
|
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
2016-08-21 17:55:56 -04:00
|
|
|
|
|
|
|
try:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['speechDriver'].setVolume(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'volume'))
|
2016-08-21 17:55:56 -04:00
|
|
|
except Exception as e:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['debug'].writeDebugOut("setting speech volume in outputManager.speakText ",debug.debugLevel.ERROR)
|
|
|
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
2016-08-21 17:55:56 -04:00
|
|
|
|
|
|
|
try:
|
2016-09-22 16:42:14 -04:00
|
|
|
text = self.env['runtime']['punctuationManager'].proceedPunctuation(text,ignorePunctuation)
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['speechDriver'].speak(text)
|
2016-08-21 17:55:56 -04:00
|
|
|
except Exception as e:
|
2016-09-22 16:42:14 -04:00
|
|
|
print(e)
|
2016-09-21 17:17:54 -04:00
|
|
|
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
|
|
|
|
2016-09-21 17:17:54 -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
|
2016-09-21 17:17:54 -04:00
|
|
|
if self.env['runtime']['brailleDriver'] == None:
|
2016-07-26 10:19:23 -04:00
|
|
|
return
|
2016-08-08 05:07:40 -04:00
|
|
|
print('braille:'+text)
|
2016-07-26 17:39:22 -04:00
|
|
|
|
2016-09-21 17:17:54 -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()
|
2016-09-21 17:17:54 -04:00
|
|
|
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
|
2016-08-21 17:55:56 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
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:
|
2016-09-21 17:17:54 -04:00
|
|
|
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
|
2016-08-21 17:55:56 -04:00
|
|
|
except Exception as e:
|
2016-09-21 17:17:54 -04:00
|
|
|
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
|