make python package and build up class model
This commit is contained in:
parent
1f07f3f6e7
commit
74a4341436
@ -1,68 +0,0 @@
|
||||
#!/bin/python
|
||||
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
|
||||
import hashlib
|
||||
import difflib
|
||||
import textwrap
|
||||
import time
|
||||
|
||||
import utils.debug
|
||||
import core.environment as environment
|
||||
import speech.espeak as es
|
||||
import speech.speechd as sd
|
||||
|
||||
runtime = environment.runtime
|
||||
runtime['screenDriver'] = '/dev/vcsa'
|
||||
runtime['speechDriverString'] = 'speechd'
|
||||
runtime['speechDriver'] = sd.speech()
|
||||
|
||||
while(runtime['running']):
|
||||
# read screen
|
||||
currTTY = open('/sys/devices/virtual/tty/tty0/active','r')
|
||||
runtime['newTTY'] = currTTY.read()[3:-1]
|
||||
currTTY.close()
|
||||
|
||||
try:
|
||||
vcsa = open(runtime['screenDriver'] + runtime['newTTY'] ,'rb',0)
|
||||
runtime['newContentBytes'] = vcsa.read()
|
||||
vcsa.close()
|
||||
except:
|
||||
continue
|
||||
|
||||
# get metadata like cursor or screensize
|
||||
runtime['lines'] = int( runtime['newContentBytes'][0])
|
||||
runtime['columns'] = int( runtime['newContentBytes'][1])
|
||||
runtime['newCursor']['x'] = int( runtime['newContentBytes'][2])
|
||||
runtime['newCursor']['y'] = int( runtime['newContentBytes'][3])
|
||||
|
||||
# analyze content
|
||||
|
||||
runtime['newContentText'] = str(runtime['newContentBytes'][4:][::2].decode('cp1252').encode('utf-8'))[2:]
|
||||
runtime['newContentAttrib'] = runtime['newContentBytes'][5:][::2]
|
||||
runtime['newContentText'] = '\n'.join(textwrap.wrap(runtime['newContentText'], runtime['columns']))[:-2]
|
||||
print("|"+runtime['newContentText'] +"|")
|
||||
print(runtime['newTTY'])
|
||||
if runtime['newTTY'] != runtime['oldTTY']:
|
||||
runtime['oldContentBytes'] = b''
|
||||
runtime['oldContentAttrib'] = b''
|
||||
runtime['oldContentText'] = ''
|
||||
runtime['oldCursor']['x'] = 0
|
||||
runtime['oldCursor']['y'] = 0
|
||||
|
||||
# changes on the screen
|
||||
if runtime['oldContentBytes'] != runtime['newContentBytes']:
|
||||
if ((len(runtime['delta']) < 3) or runtime['oldTTY'] != runtime['newTTY']):
|
||||
runtime['speechDriver'].cancel()
|
||||
diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText'])
|
||||
runtime['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
|
||||
runtime['speechDriver'].speak(runtime['delta'])
|
||||
|
||||
# set new "old" values
|
||||
runtime['oldContentBytes'] = runtime['newContentBytes']
|
||||
runtime['oldContentText'] = runtime['newContentText']
|
||||
runtime['oldContentTextAttrib'] = runtime['newContentAttrib']
|
||||
runtime['oldCursor']['x'] = runtime['newCursor']['x']
|
||||
runtime['oldCursor']['y'] = runtime['newCursor']['y']
|
||||
runtime['oldTTY'] = runtime['newTTY']
|
@ -1 +0,0 @@
|
||||
#!/bin/python
|
@ -1,3 +0,0 @@
|
||||
espeak = espeak driver
|
||||
speechd = speech-dispatcher driver
|
||||
generic = generic driver via /bin/say
|
@ -1,54 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Espeak driver
|
||||
|
||||
class speech():
|
||||
def __init__(self, ):
|
||||
self._es = None
|
||||
self._isInitialized = False
|
||||
try:
|
||||
from espeak import espeak
|
||||
self._es = espeak
|
||||
self._isInitialized = True
|
||||
except:
|
||||
self._initialized = False
|
||||
|
||||
|
||||
def speak(self,text, queueable=True):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
if queueable == False: self.cancel()
|
||||
self._es.synth(text)
|
||||
return True
|
||||
|
||||
def cancel(self):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
self._es.cancel()
|
||||
return True
|
||||
|
||||
def clear_buffer(self):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
return True
|
||||
|
||||
def setVoice(self, voice):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
return _es.set_voice('de')
|
||||
|
||||
def setPitch(self, pitch):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
return _es.set_parameter(espeak.Parameter.Pitch, pitch)
|
||||
|
||||
def setSpeed(self, speed):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
return _es.set_parameter(espeak.Parameter.Rate, speed)
|
||||
|
||||
def setModule(self, module):
|
||||
pass
|
||||
|
||||
def shutdown(self):
|
||||
pass
|
@ -1,20 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Generic speech driver
|
||||
|
||||
class speech():
|
||||
def __init__(self, ):
|
||||
self.gn = None
|
||||
self.isInitialized = False
|
||||
# try:
|
||||
|
||||
|
||||
def speak(self,text, queueable=True):
|
||||
if queueable == False: self.stop()
|
||||
self.gn.synth(text)
|
||||
|
||||
def stop(self):
|
||||
self.gn.cancel()
|
||||
|
||||
def clear_buffer(self):
|
||||
pass
|
@ -1,74 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# speech-dispatcher driver
|
||||
|
||||
class speech():
|
||||
def __init__(self ):
|
||||
self._sd = None
|
||||
self._isInitialized = False
|
||||
try:
|
||||
import speechd
|
||||
self._sd = speechd.SSIPClient('fenrir')
|
||||
self._isInitialized = True
|
||||
except:
|
||||
self._initialized = False
|
||||
|
||||
|
||||
def speak(self,text, queueable=True):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
if queueable == False: self.cancel()
|
||||
self._sd.speak(text)
|
||||
return True
|
||||
|
||||
def cancel(self):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
self._sd.cancel()
|
||||
return True
|
||||
|
||||
def clear_buffer(self):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
return True
|
||||
|
||||
def setVoice(self, voice):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
try:
|
||||
self._sd.set_voice(voice)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def setPitch(self, pitch):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
try:
|
||||
self._sd.set_pitch(pitch)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def setSpeed(self, speed):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
try:
|
||||
self._sd.set_rate(speed)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def setModule(self, module):
|
||||
if not self._isInitialized:
|
||||
return False
|
||||
try:
|
||||
self._sd.set_output_module(module)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def shutdown(self):
|
||||
self.cancel()
|
||||
self._sd.close()
|
@ -1,78 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script configures pulse to work both in the graphical invironment and in the console with root apps.
|
||||
|
||||
# Make sure we aren't started as root:
|
||||
if [[ $(whoami) = "root" ]]; then
|
||||
echo "Please don't start this script with root priveleges, the script will call sudo when needed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the current user's XDG_HOME
|
||||
xdgPath="${XDG_CONFIG_HOME:-$HOME/.config}"
|
||||
|
||||
# Warn user if we are going to overwrite an existing default.pa
|
||||
if [ -f "$xdgPath/pulse/default.pa" ]; then
|
||||
read -p "This will replace the current file located at $xdgPath/pulse/default.pa, press enter to continue or control+c to abort. " continue
|
||||
fi
|
||||
echo '.include /etc/pulse/default.pa
|
||||
load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulse.sock' > $xdgPath/pulse/default.pa
|
||||
|
||||
# This section does the root part:
|
||||
read -p "This next sections requires root priveleges.. If you don't have access to sudo, please control c to abort this script, if you can use sudo, press enter to continue. " continue
|
||||
|
||||
|
||||
# Get root's 's XDG_HOME
|
||||
xdgPath="$(sudo bash -c '${XDG_CONFIG_HOME:-$HOME/.config}')"
|
||||
|
||||
# Warn user if we are going to overwrite an existing default.pa
|
||||
if [ -f "$xdgPath/pulse/default.pa" ]; then
|
||||
read -p "This will replace the current file located at $xdgPath/pulse/default.pa, press enter to continue or control+c to abort. " continue
|
||||
fi
|
||||
|
||||
sudo cat << EOF > "$xdgPath/pulse/client.conf"
|
||||
# This file is part of PulseAudio.
|
||||
#
|
||||
# PulseAudio is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# PulseAudio is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
## Configuration file for PulseAudio clients. See pulse-client.conf(5) for
|
||||
## more information. Default values are commented out. Use either ; or # for
|
||||
## commenting.
|
||||
|
||||
; default-sink =
|
||||
; default-source =
|
||||
default-server = unix:/tmp/pulse.sock
|
||||
; default-dbus-server =
|
||||
|
||||
autospawn = no
|
||||
; autospawn = yes
|
||||
; daemon-binary = /usr/bin/pulseaudio
|
||||
; extra-arguments = --log-target=syslog
|
||||
|
||||
; cookie-file =
|
||||
|
||||
; enable-shm = yes
|
||||
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
|
||||
|
||||
; auto-connect-localhost = no
|
||||
; auto-connect-display = no
|
||||
EOF
|
||||
|
||||
# If there were no errors tell user to restart, else warn them errors happened.
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Configuration created succeswsfully, restart pulse, or your system, for changes to take affect."
|
||||
else
|
||||
echo "Errors were encountered while writing the configuration. please correct them manually."
|
||||
fi
|
||||
exit 0
|
@ -1,49 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Debugger module for the Fenrir screen reader.
|
||||
ERROR = 0
|
||||
WARNING = 1
|
||||
INFO = 2
|
||||
|
||||
class debug():
|
||||
def __init__(self, fileName='/var/log/fenrir.log', level = ERROR):
|
||||
self._level = level
|
||||
self._fileName= fileName
|
||||
self._file = open(self._fileName,'w')
|
||||
self._fileOpened = True
|
||||
|
||||
def openDebugFile(self, fileName = ''):
|
||||
if fileName != '':
|
||||
self._fileName = fileName
|
||||
if self._fileName != '':
|
||||
self.file = open(self._fileName,'w')
|
||||
self._fileOpened = True
|
||||
|
||||
def writeLog(self, text, level = ERROR):
|
||||
if not self._fileOpened:
|
||||
return False
|
||||
if self._level < level:
|
||||
return False
|
||||
self._file.write(text + '\n')
|
||||
return True
|
||||
|
||||
def closeDebugFile(self):
|
||||
if not self._fileOpened:
|
||||
return False
|
||||
self._file.close()
|
||||
self._fileOpened = False
|
||||
return True
|
||||
|
||||
def getDebugLevel(self):
|
||||
return self._level
|
||||
|
||||
def setDebugLevel(self, level):
|
||||
self._level = level
|
||||
|
||||
def getDebugFile(self):
|
||||
return self._fileName
|
||||
|
||||
def setDebugFile(self, fileName):
|
||||
self._fileName = fileName
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user