From cd49aa3dca1b7cfd63349bccc4fb7e1b27cb30de Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 24 Oct 2017 07:34:22 +0200 Subject: [PATCH 01/17] start inherit drivers --- src/fenrir/brailleDriver/dummyDriver.py | 49 +---------------- src/fenrir/inputDriver/dummyDriver.py | 50 ++--------------- src/fenrir/soundDriver/dummyDriver.py | 49 +---------------- src/fenrir/soundDriver/genericDriver.py | 20 ++----- src/fenrir/soundDriver/gstreamerDriver.py | 14 +---- src/fenrir/speechDriver/dummyDriver.py | 64 +--------------------- src/fenrir/speechDriver/emacspeakDriver.py | 24 +------- src/fenrir/speechDriver/espeakDriver.py | 39 +++---------- src/fenrir/speechDriver/speechdDriver.py | 53 ++++++------------ 9 files changed, 50 insertions(+), 312 deletions(-) diff --git a/src/fenrir/brailleDriver/dummyDriver.py b/src/fenrir/brailleDriver/dummyDriver.py index 91a7c2ba..be13dd4d 100644 --- a/src/fenrir/brailleDriver/dummyDriver.py +++ b/src/fenrir/brailleDriver/dummyDriver.py @@ -5,51 +5,8 @@ # By Chrys, Storm Dragon, and contributers. from core import debug +from core.brailleDriver import brailleDriver -class driver(): +class driver(brailleDriver): def __init__(self): - self.printMessages = False - - def initialize(self, environment): - self.env = environment - self._isInitialized = True - self.deviceSize = (40,0) - if self.printMessages: - print('BrailleDummyDriver: Initialize') - - - def getDeviceSize(self): - if not self._isInitialized: - return (0,0) - if self.printMessages: - print('BrailleDummyDriver: getDeviceSize ' + str(self.deviceSize)) - return self.deviceSize - - def writeText(self,text): - if not self._isInitialized: - return - if self.printMessages: - print('BrailleDummyDriver: writeText:' + str(text)) - print('BrailleDummyDriver: -----------------------------------') - - def connectDevice(self): - if self.printMessages: - print('BrailleDummyDriver: connectDevice') - - def enterScreen(self, screen): - if not self._isInitialized: - return - if self.printMessages: - print('BrailleDummyDriver: enterScreen') - - def leveScreen(self): - if not self._isInitialized: - return - if self.printMessages: - print('BrailleDummyDriver: leveScreen') - - def shutdown(self): - if not self._isInitialized: - return - if self.printMessages: - print('BrailleDummyDriver: Shutdown') + brailleDriver.__init__(self) diff --git a/src/fenrir/inputDriver/dummyDriver.py b/src/fenrir/inputDriver/dummyDriver.py index 4a1f4fa0..0f67a44f 100644 --- a/src/fenrir/inputDriver/dummyDriver.py +++ b/src/fenrir/inputDriver/dummyDriver.py @@ -6,55 +6,13 @@ import time from core import debug +from core.inputDriver import inputDriver -class driver(): +class driver(inputDriver): def __init__(self): - self._initialized = False - - def initialize(self, environment): - self.env = environment - - def shutdown(self): - pass - + inputDriver.__init__(self) + def getInputEvent(self): time.sleep(0.05) if not self._initialized: return None - - def writeEventBuffer(self): - if not self._initialized: - return - - def clearEventBuffer(self): - if not self._initialized: - return - del self.env['input']['eventBuffer'][:] - - def updateInputDevices(self, force = False, init = False): - if not self._initialized: - return - - def getLedState(self, led = 0): - if not self._initialized: - return False - return False - - def toggleLedState(self, led = 0): - if not self._initialized: - return None - - def grabDevices(self): - if not self._initialized: - return None - - def releaseDevices(self): - if not self._initialized: - return None - - def __del__(self): - if not self._initialized: - return None - self.releaseDevices() - - diff --git a/src/fenrir/soundDriver/dummyDriver.py b/src/fenrir/soundDriver/dummyDriver.py index 4b9079c5..87e8a6a1 100644 --- a/src/fenrir/soundDriver/dummyDriver.py +++ b/src/fenrir/soundDriver/dummyDriver.py @@ -5,51 +5,8 @@ # By Chrys, Storm Dragon, and contributers. from core import debug +from core.soundDriver import soundDriver -class driver(): +class driver(soundDriver): def __init__(self): - self.volume = None - self._initialized = False - - def initialize(self, environment): - self.env = environment - self._initialized = True - print('SoundDummyDriver: Initialize') - - def shutdown(self): - if not self._initialized: - return - self.cancel() - print('SoundDummyDriver: Shutdown') - - def playFrequence(self, frequence = 1000, duration = 0.3, adjustVolume = 0): - if not self._initialized: - return - if interrupt: - self.cancel() - print('SoundDummyDriver: playFrequence:' + ' freq:' + str(frequence) + ' duration:' + str(duration) + ' adjustVolume:' + str(adjustVolume) ) - print('SoundDummyDriver: -----------------------------------') - - def playSoundFile(self, filePath, interrupt = True): - if not self._initialized: - return - if interrupt: - self.cancel() - print('SoundDummyDriver: playSoundFile:' + str(filePath)) - print('SoundDummyDriver: -----------------------------------') - - def cancel(self): - if not self._initialized: - return - print('SoundDummyDriver: Cancel') - - def setCallback(self, callback): - if not self._initialized: - return - print('SoundDummyDriver: setCallback') - - def setVolume(self, volume): - if not self._initialized: - return - self.volume = volume - print('SoundDummyDriver: setVolume:' + str(self.volume)) + soundDriver.__init__(self) diff --git a/src/fenrir/soundDriver/genericDriver.py b/src/fenrir/soundDriver/genericDriver.py index cea0c168..5a85d6f4 100644 --- a/src/fenrir/soundDriver/genericDriver.py +++ b/src/fenrir/soundDriver/genericDriver.py @@ -6,15 +6,15 @@ from core import debug import subprocess +from core.soundDriver import soundDriver -class driver(): +class driver(soundDriver): def __init__(self): + soundDriver.__init__(self) self.proc = None - self.volume = 1.0 self.soundType = '' self.soundFileCommand = '' self.frequenceCommand = '' - self._initialized = False def initialize(self, environment): self.env = environment self.soundFileCommand = self.env['runtime']['settingsManager'].getSetting('sound', 'genericPlayFileCommand') @@ -24,10 +24,7 @@ class driver(): if self.frequenceCommand == '': self.frequenceCommand = 'play -q -v fenrirVolume -n -c1 synth fenrirDuration sine fenrirFrequence' self._initialized = True - def shutdown(self): - if not self._initialized: - return - self.cancel() + def playFrequence(self, frequence = 1000, duration = 0.3, adjustVolume = 0): if not self._initialized: return @@ -56,11 +53,4 @@ class driver(): self.proc.kill() if self.soundType == 'frequence': self.proc.kill() - self.soundType = '' - def setCallback(self, callback): - if not self._initialized: - return - def setVolume(self, volume): - if not self._initialized: - return - self.volume = volume + self.soundType = '' diff --git a/src/fenrir/soundDriver/gstreamerDriver.py b/src/fenrir/soundDriver/gstreamerDriver.py index b7ed86a1..33565d53 100644 --- a/src/fenrir/soundDriver/gstreamerDriver.py +++ b/src/fenrir/soundDriver/gstreamerDriver.py @@ -6,7 +6,7 @@ from core import debug import time, threading - +from core.soundDriver import soundDriver _gstreamerAvailable = False try: @@ -19,12 +19,11 @@ except Exception as e: _gstreamerAvailable = False _availableError = str(e) -class driver: +class driver(soundDriver): def __init__(self): + soundDriver.__init__(self) self._source = None self._sink = None - self.volume = 1 - self._initialized = False def initialize(self, environment): self.env = environment @@ -112,10 +111,3 @@ class driver: return self._player.set_state(Gst.State.NULL) self._pipeline.set_state(Gst.State.NULL) - def setVolume(self, volume): - if not self._initialized: - return - self.volume = volume - - - diff --git a/src/fenrir/speechDriver/dummyDriver.py b/src/fenrir/speechDriver/dummyDriver.py index 312b375d..5d7207db 100644 --- a/src/fenrir/speechDriver/dummyDriver.py +++ b/src/fenrir/speechDriver/dummyDriver.py @@ -6,65 +6,7 @@ # generic driver from core import debug - -class driver(): +from core.speechDriver import speechDriver +class driver(speechDriver): def __init__(self): - pass - def initialize(self, environment): - self._isInitialized = True - self.env = environment - print('SpeechDummyDriver: Iitialize') - - def shutdown(self): - print('SpeechDummyDriver: Shutdown') - - def speak(self,text, queueable=True): - if not self._isInitialized: - return - if not queueable: - self.cancel() - print('SpeechDummyDriver: Speak:'+text) - print('SpeechDummyDriver: -----------------------------------') - - def cancel(self): - if not self._isInitialized: - return - print('SpeechDummyDriver: Cancel') - - def setCallback(self, callback): - print('SpeechDummyDriver: setCallback') - - def clear_buffer(self): - if not self._isInitialized: - return - print('SpeechDummyDriver: clear_buffer') - - def setVoice(self, voice): - if not self._isInitialized: - return - print('SpeechDummyDriver: setVoice:' + str(voice)) - - def setPitch(self, pitch): - if not self._isInitialized: - return - print('SpeechDummyDriver: setPitch:' + str(pitch)) - - def setRate(self, rate): - if not self._isInitialized: - return - print('SpeechDummyDriver: setRate:' + str(rate)) - - def setModule(self, module): - if not self._isInitialized: - return - print('SpeechDummyDriver: setModule:' + str(module)) - - def setLanguage(self, language): - if not self._isInitialized: - return - print('SpeechDummyDriver: setLanguage:' + str(language)) - - def setVolume(self, volume): - if not self._isInitialized: - return - print('SpeechDummyDriver: setVolume:' + str(volume)) + speechDriver.__init__(self) diff --git a/src/fenrir/speechDriver/emacspeakDriver.py b/src/fenrir/speechDriver/emacspeakDriver.py index 9139b334..b6d9511b 100644 --- a/src/fenrir/speechDriver/emacspeakDriver.py +++ b/src/fenrir/speechDriver/emacspeakDriver.py @@ -10,12 +10,12 @@ from subprocess import Popen, PIPE import pexpect import sys import time +from core.speechDriver import speechDriver -class driver(): +class driver(speechDriver): def __init__(self): - pass + speechDriver.__init__(self) def initialize(self, environment): - self._isInitialized = False self.env = environment try: self.server = pexpect.spawnu('tclsh ' + self.env['runtime']['settingsManager'].getSetting('speech', 'serverPath')) @@ -55,20 +55,6 @@ class driver(): except Exception as e: self.env['runtime']['debug'].writeDebugOut('speechDriver:cancel:self.server.sendline():' + str(e),debug.debugLevel.ERROR) - def setCallback(self, callback): - pass - - def clear_buffer(self): - if not self._isInitialized: - return - - def setVoice(self, voice): - if not self._isInitialized: - return - - def setPitch(self, pitch): - pass - def setRate(self, rate): if not self._isInitialized: return @@ -77,11 +63,7 @@ class driver(): except Exception as e: self.env['runtime']['debug'].writeDebugOut('speechDriver:setRate:self.server.sendline():' + str(e),debug.debugLevel.ERROR) - def setModule(self, module): - pass def setLanguage(self, language): if not self._isInitialized: return self.server.sendline('set_lang ' + language + '') - def setVolume(self, volume): - pass diff --git a/src/fenrir/speechDriver/espeakDriver.py b/src/fenrir/speechDriver/espeakDriver.py index 5767c3e5..35058817 100644 --- a/src/fenrir/speechDriver/espeakDriver.py +++ b/src/fenrir/speechDriver/espeakDriver.py @@ -6,11 +6,12 @@ # Espeak driver from core import debug +from core.speechDriver import speechDriver -class driver(): +class driver(speechDriver): def __init__(self): + speechDriver.__init__(self) self._es = None - self._isInitialized = False def initialize(self, environment): self.env = environment @@ -21,15 +22,18 @@ class driver(): except Exception as e: self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) self._initialized = False - - def shutdown(self): - pass def speak(self,text, interrupt=True): if not self._isInitialized: return if not interrupt: self.cancel() + if self.language != None: + if self.language != '': + self._es.set_voice(self.language) + elif self.voice != None: + if self.voice != '': + self._es.set_voice(self.voice) self._es.synth(text) def cancel(self): @@ -38,20 +42,6 @@ class driver(): self._es.cancel() return True - def setCallback(self, callback): - pass - - def clear_buffer(self): - if not self._isInitialized: - return - - def setVoice(self, voice): - if not self._isInitialized: - return - if voice =='': - return - return self._es.set_voice(voice) - def setPitch(self, pitch): if not self._isInitialized: return @@ -62,17 +52,6 @@ class driver(): return return self._es.set_parameter(self._es.Parameter().Rate, int(rate * 500 + 100)) - def setModule(self, module): - if not self._isInitialized: - return - - def setLanguage(self, language): - if not self._isInitialized: - return - if language =='': - return - return self._es.set_voice(language) - def setVolume(self, volume): if not self._isInitialized: return diff --git a/src/fenrir/speechDriver/speechdDriver.py b/src/fenrir/speechDriver/speechdDriver.py index f592bbbb..90014597 100644 --- a/src/fenrir/speechDriver/speechdDriver.py +++ b/src/fenrir/speechDriver/speechdDriver.py @@ -6,12 +6,12 @@ # speech-dispatcher driver from core import debug +from core.speechDriver import speechDriver -class driver(): +class driver(speechDriver): def __init__(self): + speechDriver.__init__(self) self._sd = None - self._isInitialized = False - self._language = '' def initialize(self, environment): self.env = environment @@ -22,7 +22,6 @@ class driver(): self._isInitialized = True except Exception as e: self.env['runtime']['debug'].writeDebugOut('speechDriver initialize:' + str(e),debug.debugLevel.ERROR) - self._initialized = False def shutdown(self): if not self._isInitialized: @@ -42,7 +41,18 @@ class driver(): if not self._isInitialized: return try: - self._sd.set_synthesis_voice(self._language) + self._sd.set_output_module(self.module) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('speechDriver setModule:' + str(e),debug.debugLevel.ERROR) + + try: + if self.voice != '': + self._sd.set_voice(self.voice) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('speechDriver setVoice:' + str(e),debug.debugLevel.ERROR) + try: + if self.language != '': + self._sd.set_synthesis_voice(self.language) self._sd.set_punctuation(self._punct.NONE) self._sd.speak(text) except Exception as e: @@ -57,23 +67,7 @@ class driver(): except Exception as e: self.env['runtime']['debug'].writeDebugOut('speechDriver cancel:' + str(e),debug.debugLevel.ERROR) self._isInitialized = False - - def setCallback(self, callback): - pass - - def clear_buffer(self): - if not self._isInitialized: - return - - def setVoice(self, voice): - if not self._isInitialized: - return - try: - if voice != '': - self._sd.set_voice(voice) - except Exception as e: - self.env['runtime']['debug'].writeDebugOut('speechDriver setVoice:' + str(e),debug.debugLevel.ERROR) - + def setPitch(self, pitch): if not self._isInitialized: return @@ -88,20 +82,7 @@ class driver(): try: self._sd.set_rate(int(-100 + rate * 200)) except Exception as e: - self.env['runtime']['debug'].writeDebugOut('speechDriver setRate:' + str(e),debug.debugLevel.ERROR) - - def setModule(self, module): - if not self._isInitialized: - return - try: - self._sd.set_output_module(module) - except Exception as e: - self.env['runtime']['debug'].writeDebugOut('speechDriver setModule:' + str(e),debug.debugLevel.ERROR) - - def setLanguage(self, language): - if not self._isInitialized: - return - self._language = language + self.env['runtime']['debug'].writeDebugOut('speechDriver setRate:' + str(e),debug.debugLevel.ERROR) def setVolume(self, volume): if not self._isInitialized: From bdedc207f62e76245c8bb92eca66f9e9a493338a Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 24 Oct 2017 07:34:30 +0200 Subject: [PATCH 02/17] start inherit drivers --- src/fenrir/core/brailleDriver.py | 56 ++++ src/fenrir/core/inputDriver.py | 59 ++++ src/fenrir/core/screenDriver.py | 50 ++++ src/fenrir/core/soundDriver.py | 48 ++++ src/fenrir/core/speechDriver.py | 71 +++++ src/fenrir/screenDriver/dummyDriver.py | 12 + src/fenrir/screenDriver/ptyDriver.py | 373 +++++++++++++++++++++++++ 7 files changed, 669 insertions(+) create mode 100644 src/fenrir/core/brailleDriver.py create mode 100644 src/fenrir/core/inputDriver.py create mode 100644 src/fenrir/core/screenDriver.py create mode 100644 src/fenrir/core/soundDriver.py create mode 100644 src/fenrir/core/speechDriver.py create mode 100644 src/fenrir/screenDriver/dummyDriver.py create mode 100644 src/fenrir/screenDriver/ptyDriver.py diff --git a/src/fenrir/core/brailleDriver.py b/src/fenrir/core/brailleDriver.py new file mode 100644 index 00000000..e3c21357 --- /dev/null +++ b/src/fenrir/core/brailleDriver.py @@ -0,0 +1,56 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class brailleDriver(): + def __init__(self): + self._isInitialized = False + self.printMessages = False + + def initialize(self, environment): + self.env = environment + self.deviceSize = (40,0) + if self.printMessages: + print('BrailleDummyDriver: Initialize') + self._isInitialized = True + + def getDeviceSize(self): + if not self._isInitialized: + return (0,0) + if self.printMessages: + print('BrailleDummyDriver: getDeviceSize ' + str(self.deviceSize)) + return self.deviceSize + + def writeText(self,text): + if not self._isInitialized: + return + if self.printMessages: + print('BrailleDummyDriver: writeText:' + str(text)) + print('BrailleDummyDriver: -----------------------------------') + + def connectDevice(self): + if self.printMessages: + print('BrailleDummyDriver: connectDevice') + + def enterScreen(self, screen): + if not self._isInitialized: + return + if self.printMessages: + print('BrailleDummyDriver: enterScreen') + + def leveScreen(self): + if not self._isInitialized: + return + if self.printMessages: + print('BrailleDummyDriver: leveScreen') + + def shutdown(self): + if not self._isInitialized: + return + if self.printMessages: + print('BrailleDummyDriver: Shutdown') + self._isInitialized = False diff --git a/src/fenrir/core/inputDriver.py b/src/fenrir/core/inputDriver.py new file mode 100644 index 00000000..d1c60e79 --- /dev/null +++ b/src/fenrir/core/inputDriver.py @@ -0,0 +1,59 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class inputDriver(): + def __init__(self): + self._initialized = False + + def initialize(self, environment): + self.env = environment + self._isInitialized = True + def shutdown(self): + pass + + def getInputEvent(self): + time.sleep(0.05) + if not self._initialized: + return None + + def writeEventBuffer(self): + if not self._initialized: + return + + def clearEventBuffer(self): + if not self._initialized: + return + del self.env['input']['eventBuffer'][:] + + def updateInputDevices(self, force = False, init = False): + if not self._initialized: + return + + def getLedState(self, led = 0): + if not self._initialized: + return False + return False + + def toggleLedState(self, led = 0): + if not self._initialized: + return None + + def grabDevices(self): + if not self._initialized: + return None + + def releaseDevices(self): + if not self._initialized: + return None + + def __del__(self): + if not self._initialized: + return None + self.releaseDevices() + + diff --git a/src/fenrir/core/screenDriver.py b/src/fenrir/core/screenDriver.py new file mode 100644 index 00000000..f69ace16 --- /dev/null +++ b/src/fenrir/core/screenDriver.py @@ -0,0 +1,50 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. +#attrib: +#http://rampex.ihep.su/Linux/linux_howto/html/tutorials/mini/Colour-ls-6.html +#0 = black, 1 = blue, 2 = green, 3 = cyan, 4 = red, 5 = purple, 6 = brown/yellow, 7 = white. +#https://github.com/jwilk/vcsapeek/blob/master/linuxvt.py +#blink = 5 if attr & 1 else 0 +#bold = 1 if attr & 16 else 0 + + +from core import debug + +class screenDriver(): + def __init__(self): + self._isInitialized = False + self.bgColorNames = {0: _('black'), 1: _('blue'), 2: _('green'), 3: _('cyan'), 4: _('red'), 5: _('Magenta'), 6: _('brown/yellow'), 7: _('white')} + self.fgColorNames = {0: _('Black'), 1: _('Blue'), 2: _('Green'), 3: _('Cyan'), 4: _('Red'), 5: _('Magenta'), 6: _('brown/yellow'), 7: _('Light gray'), 8: _('Dark gray'), 9: _('Light blue'), 10: ('Light green'), 11: _('Light cyan'), 12: _('Light red'), 13: _('Light magenta'), 14: _('Light yellow'), 15: _('White')} + def initialize(self, environment): + self.env = environment + self._isInitialized = True + def shutdown(self): + pass + def getCurrScreen(self): + pass + def getCurrApplication(self): + pass + def getSessionInformation(self): + pass + def getFenrirBGColor(self, attribute): + return '' + def getFenrirFGColor(self, attribute): + return '' + def getFenrirUnderline(self, attribute): + return '' + def getFenrirBold(self, attribute): + return '' + def getFenrirBlink(self, attribute): + return '' + def getFenrirFont(self, attribute): + return '' + def getFenrirFontSize(self, attribute): + return '' + def getContent(self): + pass + def update(self, trigger='onUpdate'): + pass + diff --git a/src/fenrir/core/soundDriver.py b/src/fenrir/core/soundDriver.py new file mode 100644 index 00000000..729ea895 --- /dev/null +++ b/src/fenrir/core/soundDriver.py @@ -0,0 +1,48 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug + +class soundDriver(): + def __init__(self): + self.volume = 1.0 + self._initialized = False + + def initialize(self, environment): + self.env = environment + self._initialized = True + + def shutdown(self): + if not self._initialized: + return + self.cancel() + self._isInitialized = False + + def playFrequence(self, frequence = 1000, duration = 0.3, adjustVolume = 0): + if not self._initialized: + return + if interrupt: + self.cancel() + + + def playSoundFile(self, filePath, interrupt = True): + if not self._initialized: + return + if interrupt: + self.cancel() + + def cancel(self): + if not self._initialized: + return + + def setCallback(self, callback): + if not self._initialized: + return + + def setVolume(self, volume): + if not self._initialized: + return + self.volume = volume diff --git a/src/fenrir/core/speechDriver.py b/src/fenrir/core/speechDriver.py new file mode 100644 index 00000000..6bd6a4d8 --- /dev/null +++ b/src/fenrir/core/speechDriver.py @@ -0,0 +1,71 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. +# generic driver + +from core import debug + +class speechDriver(): + def __init__(self): + self._isInitialized = False + self.language = None + self.voice = None + self.module = None + def initialize(self, environment): + self.env = environment + self._isInitialized = True + + def shutdown(self): + self.cancel() + self._isInitialized = False + + def speak(self,text, queueable=True): + if not self._isInitialized: + return + if not queueable: + self.cancel() + + def cancel(self): + if not self._isInitialized: + return + + def setCallback(self, callback): + pass + + def clear_buffer(self): + if not self._isInitialized: + return + + def setVoice(self, voice): + if not self._isInitialized: + return + if voice =='': + return + self.voice = voice + + def setPitch(self, pitch): + if not self._isInitialized: + return + + def setRate(self, rate): + if not self._isInitialized: + return + + def setModule(self, module): + if not self._isInitialized: + return + if module =='': + return + self.module = module + + def setLanguage(self, language): + if not self._isInitialized: + return + if language =='': + return + self.language = language + def setVolume(self, volume): + if not self._isInitialized: + return diff --git a/src/fenrir/screenDriver/dummyDriver.py b/src/fenrir/screenDriver/dummyDriver.py new file mode 100644 index 00000000..6318b734 --- /dev/null +++ b/src/fenrir/screenDriver/dummyDriver.py @@ -0,0 +1,12 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from core.screenDriver import screenDriver + +class driver(screenDriver): + def __init__(self): + screenDriver.__init__(self) diff --git a/src/fenrir/screenDriver/ptyDriver.py b/src/fenrir/screenDriver/ptyDriver.py new file mode 100644 index 00000000..e50ad3d2 --- /dev/null +++ b/src/fenrir/screenDriver/ptyDriver.py @@ -0,0 +1,373 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. +#attrib: +#http://rampex.ihep.su/Linux/linux_howto/html/tutorials/mini/Colour-ls-6.html +#0 = black, 1 = blue, 2 = green, 3 = cyan, 4 = red, 5 = purple, 6 = brown/yellow, 7 = white. +#https://github.com/jwilk/vcsapeek/blob/master/linuxvt.py +#blink = 5 if attr & 1 else 0 +#bold = 1 if attr & 16 else 0 + + +import difflib +import re +import subprocess +import glob, os +import termios +import time +import select +import dbus +import fcntl +from array import array +import errno +import sys +from utils import screen_utils +from fcntl import ioctl +from struct import unpack_from, unpack, pack +from core import debug +from core.eventData import fenrirEventType + + +class driver(): + def __init__(self): + self.vcsaDevicePath = '/dev/vcsa' + self.ListSessions = None + self.charmap = {} + self.bgColorNames = {0: _('black'), 1: _('blue'), 2: _('green'), 3: _('cyan'), 4: _('red'), 5: _('Magenta'), 6: _('brown/yellow'), 7: _('white')} + self.fgColorNames = {0: _('Black'), 1: _('Blue'), 2: _('Green'), 3: _('Cyan'), 4: _('Red'), 5: _('Magenta'), 6: _('brown/yellow'), 7: _('Light gray'), 8: _('Dark gray'), 9: _('Light blue'), 10: ('Light green'), 11: _('Light cyan'), 12: _('Light red'), 13: _('Light magenta'), 14: _('Light yellow'), 15: _('White')} + self.hichar = None + def initialize(self, environment): + self.env = environment + self.env['runtime']['processManager'].addCustomEventThread(self.updateWatchdog) + def shutdown(self): + pass + def getCurrScreen(self): + self.env['screen']['oldTTY'] = self.env['screen']['newTTY'] + try: + currScreenFile = open('/sys/devices/virtual/tty/tty0/active','r') + self.env['screen']['newTTY'] = str(currScreenFile.read()[3:-1]) + currScreenFile.close() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + def injectTextToScreen(self, text, screen = None): + useScreen = "/dev/tty" + self.env['screen']['newTTY'] + if screen != None: + useScreen = screen + with open(useScreen, 'w') as fd: + for c in text: + fcntl.ioctl(fd, termios.TIOCSTI, c) + + def getCurrApplication(self): + apps = [] + try: + currScreen = self.env['screen']['newTTY'] + apps = subprocess.Popen('ps -t tty' + currScreen + ' -o comm,tty,stat', shell=True, stdout=subprocess.PIPE).stdout.read().decode()[:-1].split('\n') + except Exception as e: + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + return + try: + for i in apps: + i = i.upper() + i = i.split() + i[0] = i[0] + i[1] = i[1] + if '+' in i[2]: + if i[0] != '': + if not "GREP" == i[0] and \ + not "SH" == i[0] and \ + not "PS" == i[0]: + if "TTY"+currScreen in i[1]: + if self.env['screen']['newApplication'] != i[0]: + self.env['screen']['newApplication'] = i[0] + return + except Exception as e: + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + + def getSessionInformation(self): + try: + bus = dbus.SystemBus() + if not self.ListSessions: + obj = bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1') + inf = dbus.Interface(obj, 'org.freedesktop.login1.Manager') + self.ListSessions = inf.get_dbus_method('ListSessions') + sessions = self.ListSessions() + self.env['screen']['autoIgnoreScreens'] = [] + for session in sessions: + obj = bus.get_object('org.freedesktop.login1', session[4]) + inf = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') + sessionType = inf.Get('org.freedesktop.login1.Session', 'Type') + screen = str(inf.Get('org.freedesktop.login1.Session', 'VTNr')) + if screen == '': + screen = str(inf.Get('org.freedesktop.login1.Session', 'TTY')) + screen = screen[screen.upper().find('TTY') + 3:] + if screen == '': + self.env['runtime']['debug'].writeDebugOut('No TTY found for session:' + session[4],debug.debugLevel.ERROR) + return + if sessionType.upper() == 'X11': + self.env['screen']['autoIgnoreScreens'].append(screen) + if screen == self.env['screen']['newTTY'] : + if self.env['general']['currUser'] != session[2]: + self.env['general']['prevUser'] = self.env['general']['currUser'] + self.env['general']['currUser'] = session[2] + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('getSessionInformation: Maybe no LoginD:' + str(e),debug.debugLevel.ERROR) + self.env['screen']['autoIgnoreScreens'] = [] + self.env['runtime']['debug'].writeDebugOut('getSessionInformation:' + str(self.env['screen']['autoIgnoreScreens']) + ' ' + str(self.env['general']) ,debug.debugLevel.INFO) + + def updateWatchdog(self,active , eventQueue): + try: + vcsa = {} + vcsaDevices = glob.glob('/dev/vcsa*') + for vcsaDev in vcsaDevices: + index = vcsaDev[9:] + vcsa[str(index)] = open(vcsaDev,'rb') + + tty = open('/sys/devices/virtual/tty/tty0/active','r') + currScreen = str(tty.read()[3:-1]) + oldScreen = currScreen + watchdog = select.epoll() + watchdog.register(vcsa[currScreen], select.POLLPRI | select.POLLERR) + watchdog.register(tty, select.POLLPRI | select.POLLERR) + while active.value == 1: + changes = watchdog.poll(2) + for change in changes: + fileno = change[0] + event = change[1] + if fileno == tty.fileno(): + self.env['runtime']['debug'].writeDebugOut('ScreenChange',debug.debugLevel.INFO) + tty.seek(0) + currScreen = str(tty.read()[3:-1]) + if currScreen != oldScreen: + try: + watchdog.unregister(vcsa[ oldScreen ]) + except: + pass + try: + watchdog.register(vcsa[ currScreen ], select.POLLPRI | select.POLLERR) + except: + pass + oldScreen = currScreen + eventQueue.put({"Type":fenrirEventType.ScreenChanged,"Data":''}) + try: + vcsa[currScreen].seek(0) + lastScreenContent = vcsa[currScreen].read() + except: + pass + else: + self.env['runtime']['debug'].writeDebugOut('ScreenUpdate',debug.debugLevel.INFO) + vcsa[currScreen].seek(0) + dirtyContent = vcsa[currScreen].read() + screenContent = b'' + timeout = time.time() + while screenContent != dirtyContent: + screenContent = dirtyContent + if time.time() - timeout >= 0.4: + break + time.sleep(0.007) + vcsa[currScreen].seek(0) + dirtyContent = vcsa[currScreen].read() + eventQueue.put({"Type":fenrirEventType.ScreenUpdate,"Data":None}) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR) + + def updateCharMap(self, screen): + self.charmap = {} + try: + tty = open('/dev/tty' + screen, 'rb') + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('VCSA:updateCharMap:' + str(e),debug.debugLevel.ERROR) + return + GIO_UNIMAP = 0x4B66 + VT_GETHIFONTMASK = 0x560D + himask = array("H", (0,)) + ioctl(tty, VT_GETHIFONTMASK, himask) + self.hichar, = unpack_from("@H", himask) + sz = 512 + line = '' + while True: + try: + unipairs = array("H", [0]*(2*sz)) + unimapdesc = array("B", pack("@HP", sz, unipairs.buffer_info()[0])) + ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc) + break + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('VCSA:updateCharMap:scaling up sz=' + str(sz) + ' ' + str(e),debug.debugLevel.WARNING) + sz *= 2 + tty.close() + ncodes, = unpack_from("@H", unimapdesc) + utable = unpack_from("@%dH" % (2*ncodes), unipairs) + for u, b in zip(utable[::2], utable[1::2]): + if self.charmap.get(b) is None: + self.charmap[b] = chr(u) + + def autoDecodeVCSA(self, allData, rows, cols): + allText = '' + allAttrib = [] + i = 0 + for y in range(rows): + lineText = '' + lineAttrib = [] + for x in range(cols): + data = allData[i: i + 2] + i += 2 + if data == b' \x07': + #attr = 7 + #ink = 7 + #paper = 0 + #ch = ' ' + lineAttrib.append((7,15,0,0,0,0)) # attribute, ink, paper, blink, bold, underline + lineText += ' ' + continue + (sh,) = unpack("=H", data) + attr = (sh >> 8) & 0xFF + ch = sh & 0xFF + if self.hichar == 0x100: + attr >>= 1 + ink = attr & 0x0F + paper = (attr>>4) & 0x0F + blink = 0 + #if attr & 1: + # blink = 1 + bold = 0 + #if attr & 16: + # bold = 1 + #if (ink != 7) or (paper != 0): + # print(ink,paper) + if sh & self.hichar: + ch |= 0x100 + try: + lineText += self.charmap[ch] + except KeyError: + lineText += '?' + lineAttrib.append((attr,ink, paper,blink,bold,0)) # attribute, ink, paper, blink, bold, underline + allText += lineText + '\n' + allAttrib += lineAttrib + return str(allText), allAttrib + def getFenrirBGColor(self, attribute): + try: + return self.bgColorNames[attribute[2]] + except Exception as e: + print(e) + return '' + def getFenrirFGColor(self, attribute): + try: + return self.fgColorNames[attribute[1]] + except Exception as e: + print(e) + return '' + def getFenrirUnderline(self, attribute): + if attribute[5] == 1: + return _('underlined') + return '' + def getFenrirBold(self, attribute): + if attribute[4] == 1: + return _('bold') + return '' + def getFenrirBlink(self, attribute): + if attribute[3] == 1: + return _('blink') + return '' + def getFenrirFont(self, attribute): + return _('Default') + def getFenrirFontSize(self, attribute): + return _('Default') + def update(self, trigger='onUpdate'): + if trigger == 'onInput': # no need for an update on input for VCSA + return + newContentBytes = b'' + try: + # read screen + vcsa = open(self.vcsaDevicePath + self.env['screen']['newTTY'],'rb',0) + newContentBytes = vcsa.read() + vcsa.close() + if len(newContentBytes) < 5: + return + except Exception as e: + self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR) + return + # set new "old" values + self.env['screen']['oldContentBytes'] = self.env['screen']['newContentBytes'] + self.env['screen']['oldContentText'] = self.env['screen']['newContentText'] + self.env['screen']['oldContentAttrib'] = self.env['screen']['newContentAttrib'] + self.env['screen']['oldCursor'] = self.env['screen']['newCursor'].copy() + if self.env['screen']['newCursorAttrib']: + self.env['screen']['oldCursorAttrib'] = self.env['screen']['newCursorAttrib'].copy() + self.env['screen']['oldDelta'] = self.env['screen']['newDelta'] + self.env['screen']['oldAttribDelta'] = self.env['screen']['newAttribDelta'] + self.env['screen']['oldNegativeDelta'] = self.env['screen']['newNegativeDelta'] + self.env['screen']['newContentBytes'] = newContentBytes + # get metadata like cursor or screensize + self.env['screen']['lines'] = int( self.env['screen']['newContentBytes'][0]) + self.env['screen']['columns'] = int( self.env['screen']['newContentBytes'][1]) + self.env['screen']['newCursor']['x'] = int( self.env['screen']['newContentBytes'][2]) + self.env['screen']['newCursor']['y'] = int( self.env['screen']['newContentBytes'][3]) + + # analyze content + self.updateCharMap(str(self.env['screen']['newTTY'])) + self.env['screen']['newContentText'], \ + self.env['screen']['newContentAttrib'] =\ + self.autoDecodeVCSA(self.env['screen']['newContentBytes'][4:], self.env['screen']['lines'], self.env['screen']['columns']) + + if self.env['screen']['newTTY'] != self.env['screen']['oldTTY']: + self.env['screen']['oldContentBytes'] = b'' + self.env['screen']['oldContentAttrib'] = None + self.env['screen']['oldContentText'] = '' + self.env['screen']['oldCursor']['x'] = 0 + self.env['screen']['oldCursor']['y'] = 0 + self.env['screen']['oldDelta'] = '' + self.env['screen']['oldAttribDelta'] = '' + self.env['screen']['oldCursorAttrib'] = None + self.env['screen']['newCursorAttrib'] = None + self.env['screen']['oldNegativeDelta'] = '' + # initialize current deltas + self.env['screen']['newNegativeDelta'] = '' + self.env['screen']['newDelta'] = '' + self.env['screen']['newAttribDelta'] = '' + + # changes on the screen + oldScreenText = re.sub(' +',' ',self.env['runtime']['screenManager'].getWindowAreaInText(self.env['screen']['oldContentText'])) + newScreenText = re.sub(' +',' ',self.env['runtime']['screenManager'].getWindowAreaInText(self.env['screen']['newContentText'])) + typing = False + if (self.env['screen']['oldContentText'] != self.env['screen']['newContentText']): + if self.env['screen']['newContentText'] != '' and self.env['screen']['oldContentText'] == '': + if oldScreenText == '' and\ + newScreenText != '': + self.env['screen']['newDelta'] = newScreenText + else: + cursorLineStart = self.env['screen']['newCursor']['y'] * self.env['screen']['columns'] + self.env['screen']['newCursor']['y'] + cursorLineEnd = cursorLineStart + self.env['screen']['columns'] + if abs(self.env['screen']['oldCursor']['x'] - self.env['screen']['newCursor']['x']) == 1 and \ + self.env['screen']['oldCursor']['y'] == self.env['screen']['newCursor']['y'] and \ + self.env['screen']['newContentText'][:cursorLineStart] == self.env['screen']['oldContentText'][:cursorLineStart] and \ + self.env['screen']['newContentText'][cursorLineEnd:] == self.env['screen']['oldContentText'][cursorLineEnd:]: + cursorLineStartOffset = cursorLineStart + cursorLineEndOffset = cursorLineEnd + #if cursorLineStart < cursorLineStart + self.env['screen']['newCursor']['x'] - 4: + # cursorLineStartOffset = cursorLineStart + self.env['screen']['newCursor']['x'] - 4 + if cursorLineEnd > cursorLineStart + self.env['screen']['newCursor']['x'] + 3: + cursorLineEndOffset = cursorLineStart + self.env['screen']['newCursor']['x'] + 3 + oldScreenText = self.env['screen']['oldContentText'][cursorLineStartOffset:cursorLineEndOffset] + oldScreenText = re.sub(' +',' ',oldScreenText) + newScreenText = self.env['screen']['newContentText'][cursorLineStartOffset:cursorLineEndOffset] + newScreenText = re.sub(' +',' ',newScreenText) + diff = difflib.ndiff(oldScreenText, newScreenText) + typing = True + else: + diff = difflib.ndiff( oldScreenText.split('\n'),\ + newScreenText.split('\n')) + + diffList = list(diff) + + if self.env['runtime']['settingsManager'].getSetting('general', 'newLinePause') and not typing: + self.env['screen']['newDelta'] = '\n'.join(x[2:] for x in diffList if x[0] == '+') + else: + self.env['screen']['newDelta'] = ''.join(x[2:] for x in diffList if x[0] == '+') + self.env['screen']['newNegativeDelta'] = ''.join(x[2:] for x in diffList if x[0] == '-') + + # track highlighted + if self.env['screen']['oldContentAttrib'] != self.env['screen']['newContentAttrib']: + if self.env['runtime']['settingsManager'].getSettingAsBool('focus', 'highlight'): + self.env['screen']['newAttribDelta'], self.env['screen']['newCursorAttrib'] = screen_utils.trackHighlights(self.env['screen']['oldContentAttrib'], self.env['screen']['newContentAttrib'], self.env['screen']['newContentText'], self.env['screen']['columns']) + From 6b3a89a837f1e0d33c7f3577050ea58eef7061da Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 24 Oct 2017 07:39:02 +0200 Subject: [PATCH 03/17] start inherit more drivers --- src/fenrir/core/inputDriver.py | 24 ++++++------------------ src/fenrir/inputDriver/evdevDriver.py | 15 ++++----------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/fenrir/core/inputDriver.py b/src/fenrir/core/inputDriver.py index d1c60e79..39593d26 100644 --- a/src/fenrir/core/inputDriver.py +++ b/src/fenrir/core/inputDriver.py @@ -9,51 +9,39 @@ from core import debug class inputDriver(): def __init__(self): self._initialized = False - def initialize(self, environment): self.env = environment - self._isInitialized = True + self._isInitialized = True def shutdown(self): - pass - + self._isInitialized = False def getInputEvent(self): time.sleep(0.05) if not self._initialized: return None - def writeEventBuffer(self): if not self._initialized: return - def clearEventBuffer(self): if not self._initialized: return del self.env['input']['eventBuffer'][:] - def updateInputDevices(self, force = False, init = False): if not self._initialized: return - def getLedState(self, led = 0): if not self._initialized: return False - return False - + return False def toggleLedState(self, led = 0): if not self._initialized: - return None - + return None def grabDevices(self): if not self._initialized: - return None - + return None def releaseDevices(self): if not self._initialized: - return None - + return None def __del__(self): if not self._initialized: return None self.releaseDevices() - - diff --git a/src/fenrir/inputDriver/evdevDriver.py b/src/fenrir/inputDriver/evdevDriver.py index 72596042..2a5e81f5 100644 --- a/src/fenrir/inputDriver/evdevDriver.py +++ b/src/fenrir/inputDriver/evdevDriver.py @@ -30,16 +30,16 @@ from ctypes import c_bool from core.eventData import fenrirEventType from core import inputData from core import debug +from core.inputDriver import inputDriver - -class driver(): +class driver(inputDriver): def __init__(self): + inputDriver.__init__(self) self._manager = multiprocessing.Manager() self.iDevices = {} self.iDevicesFD = self._manager.list() self.uDevices = {} self.iDeviceNo = 0 - self._initialized = False self.watchDog = Value(c_bool, True) def initialize(self, environment): self.env = environment @@ -70,9 +70,6 @@ class driver(): def plugInputDeviceWatchdogTimer(self, active): time.sleep(2.5) return time.time() - def shutdown(self): - if not self._initialized: - return def inputWatchdog(self,active , params): try: deviceFd = [] @@ -323,10 +320,6 @@ class driver(): self.removeDevice(fd) self.iDevices.clear() self.uDevices.clear() - self.iDeviceNo = 0 - - def __del__(self): - if not self._initialized: - return + self.iDeviceNo = 0 From bf7b74b878c8446be13a4608aabbe0a10dcee5bd Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 24 Oct 2017 07:42:06 +0200 Subject: [PATCH 04/17] start inherit more drivers --- src/fenrir/screenDriver/ptyDriver.py | 7 +++---- src/fenrir/screenDriver/vcsaDriver.py | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/fenrir/screenDriver/ptyDriver.py b/src/fenrir/screenDriver/ptyDriver.py index e50ad3d2..10b1c180 100644 --- a/src/fenrir/screenDriver/ptyDriver.py +++ b/src/fenrir/screenDriver/ptyDriver.py @@ -28,10 +28,11 @@ from fcntl import ioctl from struct import unpack_from, unpack, pack from core import debug from core.eventData import fenrirEventType +from core.screenDriver import screenDriver - -class driver(): +class driver(screenDriver): def __init__(self): + screenDriver.__init__(self) self.vcsaDevicePath = '/dev/vcsa' self.ListSessions = None self.charmap = {} @@ -41,8 +42,6 @@ class driver(): def initialize(self, environment): self.env = environment self.env['runtime']['processManager'].addCustomEventThread(self.updateWatchdog) - def shutdown(self): - pass def getCurrScreen(self): self.env['screen']['oldTTY'] = self.env['screen']['newTTY'] try: diff --git a/src/fenrir/screenDriver/vcsaDriver.py b/src/fenrir/screenDriver/vcsaDriver.py index e50ad3d2..10b1c180 100644 --- a/src/fenrir/screenDriver/vcsaDriver.py +++ b/src/fenrir/screenDriver/vcsaDriver.py @@ -28,10 +28,11 @@ from fcntl import ioctl from struct import unpack_from, unpack, pack from core import debug from core.eventData import fenrirEventType +from core.screenDriver import screenDriver - -class driver(): +class driver(screenDriver): def __init__(self): + screenDriver.__init__(self) self.vcsaDevicePath = '/dev/vcsa' self.ListSessions = None self.charmap = {} @@ -41,8 +42,6 @@ class driver(): def initialize(self, environment): self.env = environment self.env['runtime']['processManager'].addCustomEventThread(self.updateWatchdog) - def shutdown(self): - pass def getCurrScreen(self): self.env['screen']['oldTTY'] = self.env['screen']['newTTY'] try: From 4bf20aa9552b86678214a3dfebc817528a6dc878 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 24 Oct 2017 07:43:47 +0200 Subject: [PATCH 05/17] start inherit more drivers --- src/fenrir/core/screenDriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fenrir/core/screenDriver.py b/src/fenrir/core/screenDriver.py index f69ace16..165b543e 100644 --- a/src/fenrir/core/screenDriver.py +++ b/src/fenrir/core/screenDriver.py @@ -22,7 +22,7 @@ class screenDriver(): self.env = environment self._isInitialized = True def shutdown(self): - pass + self._isInitialized = False def getCurrScreen(self): pass def getCurrApplication(self): From cf46a2099a813946c87e412533aead55a9135915 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 24 Oct 2017 07:49:28 +0200 Subject: [PATCH 06/17] start inherit more drivers --- TODO v2.0 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/TODO v2.0 b/TODO v2.0 index 069557ec..c5dddc48 100644 --- a/TODO v2.0 +++ b/TODO v2.0 @@ -94,8 +94,14 @@ Application Profiles (low priority): - per application shortcuts -----------DONE---------------- -General: +General: Braille Support: Driver: +[Done] inheritation for drivers + [Done] Speech (All) + [Done] Braille (All) + [Done] Sound (All) + [Done] Input (All) + [Done] Screen (All) Settings: Application Profiles: From e9e67723084f522ef4eb8e56831bd20be095e042 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Tue, 24 Oct 2017 09:18:16 +0200 Subject: [PATCH 07/17] Update speechDriver.py --- src/fenrir/core/speechDriver.py | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/fenrir/core/speechDriver.py b/src/fenrir/core/speechDriver.py index 6bd6a4d8..c465ea08 100644 --- a/src/fenrir/core/speechDriver.py +++ b/src/fenrir/core/speechDriver.py @@ -3,7 +3,6 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -# generic driver from core import debug @@ -13,6 +12,9 @@ class speechDriver(): self.language = None self.voice = None self.module = None + self.pitch = None + self.rate = None + self.volume = None def initialize(self, environment): self.env = environment self._isInitialized = True @@ -32,7 +34,8 @@ class speechDriver(): return def setCallback(self, callback): - pass + if not callback + return def clear_buffer(self): if not self._isInitialized: @@ -41,6 +44,8 @@ class speechDriver(): def setVoice(self, voice): if not self._isInitialized: return + if not voice: + return if voice =='': return self.voice = voice @@ -48,14 +53,28 @@ class speechDriver(): def setPitch(self, pitch): if not self._isInitialized: return - + if not pitch: + return + if pitch < 0.0: + retrun + if pitch > 1.0: + return + self.pitch = pitch def setRate(self, rate): if not self._isInitialized: return - + if not rate: + return + if rate < 0.0: + retrun + if rate > 1.0: + return + self.rate = rate def setModule(self, module): if not self._isInitialized: return + if not module: + return if module =='': return self.module = module @@ -63,9 +82,18 @@ class speechDriver(): def setLanguage(self, language): if not self._isInitialized: return + if not language: + return if language =='': return self.language = language def setVolume(self, volume): if not self._isInitialized: return + if not volume: + return + if volume < 0.0: + retrun + if volume > 1.0: + return + self.volume = volume From a52a0b3dbcf7fad8a5a0cecdce39fa2c5dbe4714 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Tue, 24 Oct 2017 09:20:26 +0200 Subject: [PATCH 08/17] Update genericDriver.py --- src/fenrir/speechDriver/genericDriver.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/fenrir/speechDriver/genericDriver.py b/src/fenrir/speechDriver/genericDriver.py index 0a0912fd..39a97640 100644 --- a/src/fenrir/speechDriver/genericDriver.py +++ b/src/fenrir/speechDriver/genericDriver.py @@ -24,12 +24,6 @@ class driver(): self.speechThread = Thread(target=self.worker) self.lock = Lock() self.textQueue = speakQueue() - self.volume = '' - self.rate = '' - self.pitch = '' - self.module = '' - self.language = '' - self.voice = '' def initialize(self, environment): self.env = environment self.minVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinVolume') From c78d99427a39e5e82fca45bb37794b891da58803 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Tue, 24 Oct 2017 09:57:23 +0200 Subject: [PATCH 09/17] Update TODO v2.0 --- TODO v2.0 | 58 +++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/TODO v2.0 b/TODO v2.0 index c5dddc48..753326bc 100644 --- a/TODO v2.0 +++ b/TODO v2.0 @@ -5,10 +5,16 @@ Things needing little knowledge are marked with "(Easy for contribution)". so ju [X] = Done Cleanups: -- split oldValues := newValues out to helper function (Easy for contribution) +- generic list or see Tutorial mode list (convert clipboard management) (Easy for contribution) + [] next item + [] prev item + [] curr item + [] first item + [] last item +- split oldValues := newValues out to helper function [] split it out [] use it in vcsa driver -[] Migrate *Data.py to classes and use getter/setter (Easy for contribution) +- Migrate *Data.py to classes and use getter/setter (Easy for contribution) [] commandsData.py [] eventData.py [] generalData.py @@ -21,29 +27,22 @@ Cleanups: General: - commands -[] place last spoken to clipboard + [] place last spoken to clipboard (Easy for contribution) - imporove attribute handling -[] improve attributes_curr_char -[] add an attribute sound -[] beep on cursor/ review by char (capital wins) -[] beep on review by word (once for multiple, capital wins) -[] configurable (by char, by word, none) - https://github.com/jwilk/vcsapeek/blob/master/linuxvt.py - + [] improve attributes_curr_char + [] add an attribute sound (Easy for contribution) + [] beep on cursor/ review by char (capital wins) + [] beep on review by word (once for multiple, capital wins) + [] configurable (by char, by word, none) + https://github.com/jwilk/vcsapeek/blob/master/linuxvt.py - Improved Say all -[] all the text of all pages -[] command to stop and place review cursor at this position -[] command to slow down speech on keypress - -- generic list or see Tutorial mode list (convert clipboard management) (Easy for contribution) -[] next item -[] prev item -[] curr item -[] first item -[] last item - + [] speech callbacks + [] speech process by word + [] all the text of all pages + [] command to stop and place review cursor at this position + [] command to slow down speech on keypress - make it runnable via pypy3 -[] wrapper script for running Fenrir to check if pypy exists, use python3 as fallback. + [] wrapper script for running Fenrir to check if pypy exists, use python3 as fallback. Braille Support: [] brailleFocusMode: @@ -77,11 +76,11 @@ Driver: https://github.com/tvraman/emacspeak/blob/master/servers/obsolete/python/dectalk.py Settings: -[] write settings (Easy for contribution) -[] menue for settings configuration (Easy for contribution) + [] write settings (Easy for contribution) + [] menue for settings configuration (Easy for contribution) Application Profiles (low priority): -- reimplement process detection without subprocessing // this is started by chrys +- reimplement process detection without subprocessing - fenrir is not able to detect the current application inside of screen. ps -e -H -o pid,pgrp,ppid,tty,cmd http://stackoverflow.com/questions/24861351/how-to-detect-if-python-script-is-being-run-as-a-background-process/24862213 @@ -94,14 +93,15 @@ Application Profiles (low priority): - per application shortcuts -----------DONE---------------- -General: -Braille Support: -Driver: -[Done] inheritation for drivers +Cleanups: +- inheritation for drivers [Done] Speech (All) [Done] Braille (All) [Done] Sound (All) [Done] Input (All) [Done] Screen (All) +General: +Braille Support: +Driver: Settings: Application Profiles: From d4b0525e063f56cc7812fb84808981a13da63327 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Tue, 24 Oct 2017 15:23:44 +0200 Subject: [PATCH 10/17] Update speechDriver.py --- src/fenrir/core/speechDriver.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fenrir/core/speechDriver.py b/src/fenrir/core/speechDriver.py index c465ea08..27bb0ba9 100644 --- a/src/fenrir/core/speechDriver.py +++ b/src/fenrir/core/speechDriver.py @@ -34,7 +34,9 @@ class speechDriver(): return def setCallback(self, callback): - if not callback + if not self._isInitialized: + return + if not callback: return def clear_buffer(self): From 81ea81575d03d7c6863bc6ee4a7ccb45c9c0d5a5 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 24 Oct 2017 23:35:08 +0200 Subject: [PATCH 11/17] create debugging drivers --- src/fenrir/brailleDriver/brlapiDriver.py | 5 +- src/fenrir/brailleDriver/debugDriver.py | 49 ++++++++++++++++ src/fenrir/core/brailleDriver.py | 23 ++------ src/fenrir/core/inputDriver.py | 2 + src/fenrir/core/outputManager.py | 4 +- src/fenrir/core/screenDriver.py | 2 - src/fenrir/core/soundDriver.py | 3 +- src/fenrir/core/speechDriver.py | 23 ++++---- src/fenrir/inputDriver/debugDriver.py | 66 +++++++++++++++++++++ src/fenrir/inputDriver/dummyDriver.py | 2 +- src/fenrir/soundDriver/debugDriver.py | 56 ++++++++++++++++++ src/fenrir/speechDriver/debugDriver.py | 74 ++++++++++++++++++++++++ src/fenrir/speechDriver/dummyDriver.py | 1 + 13 files changed, 271 insertions(+), 39 deletions(-) create mode 100644 src/fenrir/brailleDriver/debugDriver.py create mode 100644 src/fenrir/inputDriver/debugDriver.py create mode 100644 src/fenrir/soundDriver/debugDriver.py create mode 100644 src/fenrir/speechDriver/debugDriver.py diff --git a/src/fenrir/brailleDriver/brlapiDriver.py b/src/fenrir/brailleDriver/brlapiDriver.py index 7c61e581..f7e63b83 100644 --- a/src/fenrir/brailleDriver/brlapiDriver.py +++ b/src/fenrir/brailleDriver/brlapiDriver.py @@ -5,10 +5,11 @@ # By Chrys, Storm Dragon, and contributers. from core import debug +from core.brailleDriver import brailleDriver -class driver(): +class driver(brailleDriver): def __init__(self): - self._isInitialized = False + brailleDriver.__init__(self) self._brl = None def initialize(self, environment): diff --git a/src/fenrir/brailleDriver/debugDriver.py b/src/fenrir/brailleDriver/debugDriver.py new file mode 100644 index 00000000..ca22bd60 --- /dev/null +++ b/src/fenrir/brailleDriver/debugDriver.py @@ -0,0 +1,49 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from core.brailleDriver import brailleDriver + +class driver(brailleDriver): + def __init__(self): + brailleDriver.__init__(self) + + def initialize(self, environment): + self.env = environment + self._isInitialized = True + self.deviceSize = (40,0) + print('Braille Debug Driver: Initialized') + + def getDeviceSize(self): + if not self._isInitialized: + return (0,0) + print('Braille Debug Driver: getDeviceSize ' + str(self.deviceSize)) + return self.deviceSize + + def writeText(self,text): + if not self._isInitialized: + return + print('Braille Debug Driver: writeText:' + str(text)) + print('Braille Debug Driver: -----------------------------------') + + def connectDevice(self): + print('Braille Debug Driver: connectDevice') + + def enterScreen(self, screen): + if not self._isInitialized: + return + print('Braille Debug Driver: enterScreen') + + def leveScreen(self): + if not self._isInitialized: + return + print('Braille Debug Driver: leveScreen') + + def shutdown(self): + if self._isInitialized: + self.leveScreen() + self._isInitialized = False + print('Braille Debug Driver: Shutdown') diff --git a/src/fenrir/core/brailleDriver.py b/src/fenrir/core/brailleDriver.py index e3c21357..a3504cec 100644 --- a/src/fenrir/core/brailleDriver.py +++ b/src/fenrir/core/brailleDriver.py @@ -9,48 +9,33 @@ from core import debug class brailleDriver(): def __init__(self): self._isInitialized = False - self.printMessages = False - + self.deviceSize = None def initialize(self, environment): self.env = environment - self.deviceSize = (40,0) - if self.printMessages: - print('BrailleDummyDriver: Initialize') self._isInitialized = True def getDeviceSize(self): if not self._isInitialized: return (0,0) - if self.printMessages: - print('BrailleDummyDriver: getDeviceSize ' + str(self.deviceSize)) - return self.deviceSize + return (0,0) def writeText(self,text): if not self._isInitialized: return - if self.printMessages: - print('BrailleDummyDriver: writeText:' + str(text)) - print('BrailleDummyDriver: -----------------------------------') def connectDevice(self): - if self.printMessages: - print('BrailleDummyDriver: connectDevice') + pass def enterScreen(self, screen): if not self._isInitialized: return - if self.printMessages: - print('BrailleDummyDriver: enterScreen') def leveScreen(self): if not self._isInitialized: return - if self.printMessages: - print('BrailleDummyDriver: leveScreen') def shutdown(self): if not self._isInitialized: return - if self.printMessages: - print('BrailleDummyDriver: Shutdown') + self.leveScreen() self._isInitialized = False diff --git a/src/fenrir/core/inputDriver.py b/src/fenrir/core/inputDriver.py index 39593d26..b17a537c 100644 --- a/src/fenrir/core/inputDriver.py +++ b/src/fenrir/core/inputDriver.py @@ -13,6 +13,8 @@ class inputDriver(): self.env = environment self._isInitialized = True def shutdown(self): + if self._initialized: + self.releaseDevices() self._isInitialized = False def getInputEvent(self): time.sleep(0.05) diff --git a/src/fenrir/core/outputManager.py b/src/fenrir/core/outputManager.py index dba07819..415f10c4 100644 --- a/src/fenrir/core/outputManager.py +++ b/src/fenrir/core/outputManager.py @@ -110,7 +110,7 @@ class outputManager(): self.env['output']['messageOffset'] = {'x':0,'y':0} self.env['output']['messageText'] = text displayText = self.getBrailleTextWithOffset(self.env['output']['messageText'], self.env['output']['messageOffset']) - self.env['runtime']['brailleDriver'].writeText('flush'+displayText) + self.env['runtime']['brailleDriver'].writeText('flush '+ displayText) else: if self.env['output']['nextFlush'] < time.time(): if self.env['output']['messageText'] != '': @@ -121,7 +121,7 @@ class outputManager(): x, y, self.env['output']['brlText'] = \ line_utils.getCurrentLine(cursor['x'], cursor['y'], self.env['screen']['newContentText']) displayText = self.getBrailleTextWithOffset(self.env['screen']['newContentText'], self.env['output']['cursorOffset'], cursor) - self.env['runtime']['brailleDriver'].writeText('notflush'+displayText) + self.env['runtime']['brailleDriver'].writeText('notflush ' + displayText) else: displayText = self.getBrailleTextWithOffset(self.env['output']['messageText'], self.env['output']['messageOffset']) self.env['runtime']['brailleDriver'].writeText('flush'+displayText) diff --git a/src/fenrir/core/screenDriver.py b/src/fenrir/core/screenDriver.py index 165b543e..418a67f0 100644 --- a/src/fenrir/core/screenDriver.py +++ b/src/fenrir/core/screenDriver.py @@ -43,8 +43,6 @@ class screenDriver(): return '' def getFenrirFontSize(self, attribute): return '' - def getContent(self): - pass def update(self, trigger='onUpdate'): pass diff --git a/src/fenrir/core/soundDriver.py b/src/fenrir/core/soundDriver.py index 729ea895..0f2d4ab7 100644 --- a/src/fenrir/core/soundDriver.py +++ b/src/fenrir/core/soundDriver.py @@ -8,7 +8,7 @@ from core import debug class soundDriver(): def __init__(self): - self.volume = 1.0 + self.volume = None self._initialized = False def initialize(self, environment): @@ -26,7 +26,6 @@ class soundDriver(): return if interrupt: self.cancel() - def playSoundFile(self, filePath, interrupt = True): if not self._initialized: diff --git a/src/fenrir/core/speechDriver.py b/src/fenrir/core/speechDriver.py index 27bb0ba9..36c9facb 100644 --- a/src/fenrir/core/speechDriver.py +++ b/src/fenrir/core/speechDriver.py @@ -20,7 +20,8 @@ class speechDriver(): self._isInitialized = True def shutdown(self): - self.cancel() + if self._isInitialized: + self.cancel() self._isInitialized = False def speak(self,text, queueable=True): @@ -28,7 +29,7 @@ class speechDriver(): return if not queueable: self.cancel() - + def cancel(self): if not self._isInitialized: return @@ -46,16 +47,16 @@ class speechDriver(): def setVoice(self, voice): if not self._isInitialized: return - if not voice: + if not isinstance(voice, float): return - if voice =='': + if voice == '': return self.voice = voice def setPitch(self, pitch): if not self._isInitialized: return - if not pitch: + if not isinstance(pitch, float): return if pitch < 0.0: retrun @@ -65,7 +66,7 @@ class speechDriver(): def setRate(self, rate): if not self._isInitialized: return - if not rate: + if not isinstance(rate, float): return if rate < 0.0: retrun @@ -75,24 +76,24 @@ class speechDriver(): def setModule(self, module): if not self._isInitialized: return - if not module: + if not isinstance(module, str): return - if module =='': + if module == '': return self.module = module def setLanguage(self, language): if not self._isInitialized: return - if not language: + if not isinstance(language, str): return - if language =='': + if language == '': return self.language = language def setVolume(self, volume): if not self._isInitialized: return - if not volume: + if not isinstance(volume,float): return if volume < 0.0: retrun diff --git a/src/fenrir/inputDriver/debugDriver.py b/src/fenrir/inputDriver/debugDriver.py new file mode 100644 index 00000000..90e4c4ce --- /dev/null +++ b/src/fenrir/inputDriver/debugDriver.py @@ -0,0 +1,66 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +import time +from core import debug +from core.inputDriver import inputDriver + +class driver(inputDriver): + def __init__(self): + inputDriver.__init__(self) + + def initialize(self, environment): + self.env = environment + self._initialized = True + print('Input Debug Driver: Initialized') + + def shutdown(self): + if self._initialized: + self.releaseDevices() + self._initialized = False + print('Input Debug Driver: Shutdown') + + def getInputEvent(self): + time.sleep(0.05) + if not self._initialized: + return None + print('Input Debug Driver: getInputEvent') + return None + def writeEventBuffer(self): + if not self._initialized: + return + print('Input Debug Driver: writeEventBuffer') + def clearEventBuffer(self): + if not self._initialized: + return + del self.env['input']['eventBuffer'][:] + print('Input Debug Driver: clearEventBuffer') + def updateInputDevices(self, force = False, init = False): + if not self._initialized: + return + print('Input Debug Driver: updateInputDevices') + def getLedState(self, led = 0): + if not self._initialized: + return False + return False + def toggleLedState(self, led = 0): + if not self._initialized: + return + print('Input Debug Driver: toggleLedState') + def grabDevices(self): + if not self._initialized: + return + print('Input Debug Driver: grabDevices') + def releaseDevices(self): + if not self._initialized: + return + print('Input Debug Driver: releaseDevices') + def __del__(self): + if self._initialized: + self.releaseDevices() + print('Input Debug Driver: __del__') + + diff --git a/src/fenrir/inputDriver/dummyDriver.py b/src/fenrir/inputDriver/dummyDriver.py index 0f67a44f..55db7f83 100644 --- a/src/fenrir/inputDriver/dummyDriver.py +++ b/src/fenrir/inputDriver/dummyDriver.py @@ -13,6 +13,6 @@ class driver(inputDriver): inputDriver.__init__(self) def getInputEvent(self): - time.sleep(0.05) + time.sleep(0.1) if not self._initialized: return None diff --git a/src/fenrir/soundDriver/debugDriver.py b/src/fenrir/soundDriver/debugDriver.py new file mode 100644 index 00000000..e782dbde --- /dev/null +++ b/src/fenrir/soundDriver/debugDriver.py @@ -0,0 +1,56 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from core.soundDriver import soundDriver + +class driver(soundDriver): + def __init__(self): + soundDriver.__init__(self) + + def initialize(self, environment): + self.env = environment + self._initialized = True + print('Sound Debug Driver: Initialized') + + def shutdown(self): + if not self._initialized: + return + self.cancel() + self._initialized = False + print('Sound Debug Driver: Shutdown') + + def playFrequence(self, frequence = 1000, duration = 0.3, adjustVolume = 0): + if not self._initialized: + return + if interrupt: + self.cancel() + print('Sound Debug Driver: playFrequence:' + ' freq:' + str(frequence) + ' duration:' + str(duration) + ' adjustVolume:' + str(adjustVolume) ) + print('Sound Debug Driver: -----------------------------------') + + def playSoundFile(self, filePath, interrupt = True): + if not self._initialized: + return + if interrupt: + self.cancel() + print('Sound Debug Driver: playSoundFile:' + str(filePath)) + print('Sound Debug Driver: -----------------------------------') + + def cancel(self): + if not self._initialized: + return + print('Sound Debug Driver: Cancel') + + def setCallback(self, callback): + if not self._initialized: + return + print('Sound Debug Driver: setCallback') + + def setVolume(self, volume): + if not self._initialized: + return + self.volume = volume + print('Sound Debug Driver: setVolume:' + str(self.volume)) diff --git a/src/fenrir/speechDriver/debugDriver.py b/src/fenrir/speechDriver/debugDriver.py new file mode 100644 index 00000000..c3ab9118 --- /dev/null +++ b/src/fenrir/speechDriver/debugDriver.py @@ -0,0 +1,74 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. +# generic driver + +from core import debug +from core.speechDriver import speechDriver + +class driver(speechDriver): + def __init__(self): + speechDriver.__init__(self + def initialize(self, environment): + self._isInitialized = True + self.env = environment + print('Speech Debug Driver: Iitialized') + + def shutdown(self): + if self._isInitialized: + self.cancel() + self._isInitialized = False + print('Speech Debug Driver: Shutdown') + + def speak(self,text, queueable=True): + if not self._isInitialized: + return + if not queueable: + self.cancel() + print('Speech Debug Driver: Speak:'+text) + print('Speech Debug Driver: -----------------------------------') + + def cancel(self): + if not self._isInitialized: + return + print('Speech Debug Driver: Cancel') + + def setCallback(self, callback): + print('Speech Debug Driver: setCallback') + + def clear_buffer(self): + if not self._isInitialized: + return + print('Speech Debug Driver: clear_buffer') + + def setVoice(self, voice): + if not self._isInitialized: + return + print('Speech Debug Driver: setVoice:' + str(voice)) + + def setPitch(self, pitch): + if not self._isInitialized: + return + print('Speech Debug Driver: setPitch:' + str(pitch)) + + def setRate(self, rate): + if not self._isInitialized: + return + print('Speech Debug Driver: setRate:' + str(rate)) + + def setModule(self, module): + if not self._isInitialized: + return + print('Speech Debug Driver: setModule:' + str(module)) + + def setLanguage(self, language): + if not self._isInitialized: + return + print('Speech Debug Driver: setLanguage:' + str(language)) + + def setVolume(self, volume): + if not self._isInitialized: + return + print('Speech Debug Driver: setVolume:' + str(volume)) diff --git a/src/fenrir/speechDriver/dummyDriver.py b/src/fenrir/speechDriver/dummyDriver.py index 5d7207db..c8ea4faa 100644 --- a/src/fenrir/speechDriver/dummyDriver.py +++ b/src/fenrir/speechDriver/dummyDriver.py @@ -7,6 +7,7 @@ from core import debug from core.speechDriver import speechDriver + class driver(speechDriver): def __init__(self): speechDriver.__init__(self) From e66acc33fce135ebc7524426171ba6496468b371 Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 25 Oct 2017 00:48:48 +0200 Subject: [PATCH 12/17] add pyttsx3 speech driver-a --- setup.py | 1 + src/fenrir/speechDriver/genericDriver.py | 4 +- src/fenrir/speechDriver/pyttsxDriver.py | 86 ++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/fenrir/speechDriver/pyttsxDriver.py diff --git a/setup.py b/setup.py index cb141f3e..c5da7d24 100755 --- a/setup.py +++ b/setup.py @@ -97,6 +97,7 @@ setup( "pyudev", "setuptools", "pexpect", + "pyttsx3", ], ) diff --git a/src/fenrir/speechDriver/genericDriver.py b/src/fenrir/speechDriver/genericDriver.py index 39a97640..7fdd40d8 100644 --- a/src/fenrir/speechDriver/genericDriver.py +++ b/src/fenrir/speechDriver/genericDriver.py @@ -9,6 +9,7 @@ from core import debug from threading import Thread, Lock from queue import Queue, Empty from subprocess import Popen +from core.speechDriver import speechDriver class speakQueue(Queue): def clear(self): @@ -18,8 +19,9 @@ class speakQueue(Queue): except Empty: pass -class driver(): +class driver(speechDriver): def __init__(self): + speechDriver.__init__(self) self.proc = None self.speechThread = Thread(target=self.worker) self.lock = Lock() diff --git a/src/fenrir/speechDriver/pyttsxDriver.py b/src/fenrir/speechDriver/pyttsxDriver.py new file mode 100644 index 00000000..1ea98e29 --- /dev/null +++ b/src/fenrir/speechDriver/pyttsxDriver.py @@ -0,0 +1,86 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. +# Espeak driver + +from threading import Thread, Lock +from core import debug +from core.speechDriver import speechDriver + +class driver(speechDriver): + def __init__(self): + speechDriver.__init__(self) + self._engine = None + def initialize(self, environment): + self.env = environment + def shutdown(self): + if self._isInitialized: + self.cancel() + self._engine.endLoop() + self._initialized = False + def eventLoop(self): + self._engine.startLoop() + def startEngine(self): + try: + import pyttsx3 + if self.module != '': + self._engine = pyttsx3.init(self.module) + else: + self._engine = pyttsx3.init() + self.eventLoopThread = Thread(target=self.eventLoop) + self._isInitialized = True + self.eventLoopThread.start() + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('SpeechDriver:initialize:' + str(e),debug.debugLevel.ERROR) + + def speak(self,text, interrupt=True): + if not self._isInitialized: + self.startEngine() + if not self._isInitialized: + return + if not interrupt: + self.cancel() + try: + self._engine.setProperty('volume', self.volume) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:volume:' + str(e),debug.debugLevel.ERROR) + try: + self._engine.setProperty('rate', self.rate) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:rate:' + str(e),debug.debugLevel.ERROR) + try: + self._engine.setProperty('pitch', self.pitch) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:pitch:' + str(e),debug.debugLevel.ERROR) + if self.language != None: + if self.language != '': + try: + self._engine.setProperty('voice', self.language) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:language:' + str(e),debug.debugLevel.ERROR) + + elif self.voice != None: + if self.voice != '': + try: + self._engine.setProperty('voice', self.voice) + except Exception as e: + self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:voice:' + str(e),debug.debugLevel.ERROR) + self._engine.say(text) + + def cancel(self): + if not self._isInitialized: + return + self._engine.stop() + self._engine.proxy.stop() + + def setPitch(self, pitch): + if not self._isInitialized: + return + self.pitch = pitch + + def setRate(self, rate): + if not self._isInitialized: + return + self.rate = rate From 3d060d23dfbf290047fa224caca6beb7d7d2018d Mon Sep 17 00:00:00 2001 From: chrys87 Date: Wed, 25 Oct 2017 09:14:03 +0200 Subject: [PATCH 13/17] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c5da7d24..ee28bf24 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ from setuptools import find_packages from setuptools import setup fenrirVersion = '1.5' -packageVersion = 'post10' +packageVersion = 'post11' # handle flags for package manager like yaourt and pacaur. forceSettings = False From 005bc7f40af769fa82ceecc0f7a586cfe61549ef Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 25 Oct 2017 23:35:45 +0200 Subject: [PATCH 14/17] add copy last echo to clipboard --- src/fenrir/core/outputManager.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fenrir/core/outputManager.py b/src/fenrir/core/outputManager.py index 415f10c4..e707bfbf 100644 --- a/src/fenrir/core/outputManager.py +++ b/src/fenrir/core/outputManager.py @@ -10,7 +10,7 @@ import string, time class outputManager(): def __init__(self): - pass + self.lastEcho = '' def initialize(self, environment): self.env = environment self.env['runtime']['settingsManager'].loadDriver(\ @@ -37,11 +37,12 @@ class outputManager(): if toAnnounceCapital: if self.playSoundIcon('capital', False): toAnnounceCapital = False - + self.lastEcho = text self.speakText(text, interrupt, ignorePunctuation,toAnnounceCapital) if flush: self.brailleText(text, flush) - + def getLastEcho(self): + return self.lastEcho def speakText(self, text, interrupt=True, ignorePunctuation=False, announceCapital=False): if not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'enabled'): self.env['runtime']['debug'].writeDebugOut("Speech disabled in outputManager.speakText",debug.debugLevel.INFO) From 5da67ce58332f77db9c3d0e02a83fa1cd0e76104 Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 25 Oct 2017 23:36:11 +0200 Subject: [PATCH 15/17] add copy last echo to clipboard --- .../commands/copy_last_echo_to_clipboard.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/fenrir/commands/commands/copy_last_echo_to_clipboard.py diff --git a/src/fenrir/commands/commands/copy_last_echo_to_clipboard.py b/src/fenrir/commands/commands/copy_last_echo_to_clipboard.py new file mode 100644 index 00000000..6a88654c --- /dev/null +++ b/src/fenrir/commands/commands/copy_last_echo_to_clipboard.py @@ -0,0 +1,28 @@ +#!/bin/python +# -*- coding: utf-8 -*- + +# Fenrir TTY screen reader +# By Chrys, Storm Dragon, and contributers. + +from core import debug +from utils import mark_utils + +class command(): + def __init__(self): + pass + def initialize(self, environment): + self.env = environment + def shutdown(self): + pass + def getDescription(self): + return _('copies last presented text to the currently selected clipboard') + + def run(self): + lastEcho = self.env['runtime']['outputManager'].getLastEcho() + self.env['commandBuffer']['clipboard'] = [lastEcho] + self.env['commandBuffer']['clipboard'][:self.env['runtime']['settingsManager'].getSettingAsInt('general', 'numberOfClipboards') -1] + self.env['commandBuffer']['currClipboard'] = 0 + + self.env['runtime']['outputManager'].presentText(lastEcho, soundIcon='CopyToClipboard', interrupt=True) + + def setCallback(self, callback): + pass From e6a0fa3b4ebacf9844118aae300304d01e28970f Mon Sep 17 00:00:00 2001 From: chrys Date: Wed, 25 Oct 2017 23:38:59 +0200 Subject: [PATCH 16/17] add unbound bindings --- config/keyboard/desktop.conf | 1 + config/keyboard/laptop.conf | 1 + 2 files changed, 2 insertions(+) diff --git a/config/keyboard/desktop.conf b/config/keyboard/desktop.conf index 8ae5e7ac..7341de07 100644 --- a/config/keyboard/desktop.conf +++ b/config/keyboard/desktop.conf @@ -105,6 +105,7 @@ KEY_FENRIR,KEY_PAGEUP=prev_clipboard KEY_FENRIR,KEY_PAGEDOWN=next_clipboard KEY_FENRIR,KEY_SHIFT,KEY_C=curr_clipboard KEY_FENRIR,KEY_C=copy_marked_to_clipboard +#=copy_last_echo_to_clipboard KEY_FENRIR,KEY_V=paste_clipboard KEY_FENRIR,KEY_F5=import_clipboard_from_file KEY_FENRIR,KEY_F6=export_clipboard_to_file diff --git a/config/keyboard/laptop.conf b/config/keyboard/laptop.conf index 45345dab..05db2e5a 100644 --- a/config/keyboard/laptop.conf +++ b/config/keyboard/laptop.conf @@ -105,6 +105,7 @@ KEY_FENRIR,KEY_PAGEUP=prev_clipboard KEY_FENRIR,KEY_PAGEDOWN=next_clipboard KEY_FENRIR,KEY_SHIFT,KEY_C=curr_clipboard KEY_FENRIR,KEY_C=copy_marked_to_clipboard +#=copy_last_echo_to_clipboard KEY_FENRIR,KEY_V=paste_clipboard KEY_FENRIR,KEY_F5=import_clipboard_from_file KEY_FENRIR,KEY_F6=export_clipboard_to_file From f6f0f7448a006867976f21ba6a3fc8d5278d3a01 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Wed, 25 Oct 2017 17:49:29 -0400 Subject: [PATCH 17/17] Keybindings for copy last utterance to clipboard set for laptop and desktop layouts. --- config/keyboard/desktop.conf | 2 +- config/keyboard/laptop.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/keyboard/desktop.conf b/config/keyboard/desktop.conf index 7341de07..cf79a144 100644 --- a/config/keyboard/desktop.conf +++ b/config/keyboard/desktop.conf @@ -105,7 +105,7 @@ KEY_FENRIR,KEY_PAGEUP=prev_clipboard KEY_FENRIR,KEY_PAGEDOWN=next_clipboard KEY_FENRIR,KEY_SHIFT,KEY_C=curr_clipboard KEY_FENRIR,KEY_C=copy_marked_to_clipboard -#=copy_last_echo_to_clipboard +KEY_FENRIR,KEY_CTRL,KEY_U=copy_last_echo_to_clipboard KEY_FENRIR,KEY_V=paste_clipboard KEY_FENRIR,KEY_F5=import_clipboard_from_file KEY_FENRIR,KEY_F6=export_clipboard_to_file diff --git a/config/keyboard/laptop.conf b/config/keyboard/laptop.conf index 05db2e5a..f07d93e5 100644 --- a/config/keyboard/laptop.conf +++ b/config/keyboard/laptop.conf @@ -105,7 +105,7 @@ KEY_FENRIR,KEY_PAGEUP=prev_clipboard KEY_FENRIR,KEY_PAGEDOWN=next_clipboard KEY_FENRIR,KEY_SHIFT,KEY_C=curr_clipboard KEY_FENRIR,KEY_C=copy_marked_to_clipboard -#=copy_last_echo_to_clipboard +KEY_FENRIR,KEY_CTRL,KEY_U=copy_last_echo_to_clipboard KEY_FENRIR,KEY_V=paste_clipboard KEY_FENRIR,KEY_F5=import_clipboard_from_file KEY_FENRIR,KEY_F6=export_clipboard_to_file