implement attribute parsing and cursor

This commit is contained in:
chrys 2016-07-05 23:18:03 +02:00
parent f0f3969366
commit 17a9901ecb
2 changed files with 50 additions and 13 deletions

View File

@ -11,11 +11,14 @@ import speech.es as es
runtime = {
'columns': 0,
'lines': 0,
'screenDriver': '/dev/vcsa3',
'delta': '',
'oldCursor':{'x':0,'y':0},
'oldContentBytes': b'',
'oldContentText': '',
'oldContentAttrib': b'',
'newCursor':{'x':0,'y':0},
'newContentBytes': b'',
'newContentText': '',
'newContentAttrib': b'',
@ -24,15 +27,23 @@ runtime = {
}
while(True):
# read screen
vcsa = open(runtime['screenDriver'],'rb')
runtime['newContentBytes'] = vcsa.read()
vcsa.close()
# get metadata like cursor or screensize
runtime['lines'] = int( runtime['newContentBytes'][0])
runtime['columns'] = int( runtime['newContentBytes'][1])
runtime['newContentText'] = str(runtime['newContentBytes'][::2].decode('cp1252').encode('utf-8'))[7:]
runtime['newContentAttrib'] = runtime['newContentBytes'][1::2][7:]
print(runtime['newContentBytes'][9])
#runtime['newContentString'] = str(runtime['newContentBytes'].decode('cp1252').encode('utf-8'))
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'))
runtime['newContentAttrib'] = runtime['newContentBytes'][5:][::2]
runtime['newContentText'] = '\n'.join(textwrap.wrap(runtime['newContentText'], runtime['columns']))
# changes on the screen
if runtime['oldContentBytes'] != runtime['newContentBytes']:
runtime['speechDriver'].stop()
print("tty3 changed")
@ -40,10 +51,12 @@ while(True):
diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText'])
runtime['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
#print(runtime['delta'])
#runtime['speechDriver'].speak(runtime['delta'])
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']

View File

@ -6,20 +6,44 @@ class speech():
def __init__(self, ):
self.es = None
self.isInitialized = False
# try:
try:
from espeak import espeak
self.es = espeak
self.isInitialized = True
# except:
# self.initialized = False
except:
self.initialized = False
def speak(self,text, queueable=True):
if not self.isInitialized:
return False
if queueable == False: self.stop()
self.es.synth(text)
return True
def stop(self):
if not self.isInitialized:
return False
self.es.cancel()
return True
def clear_buffer(self):
pass
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)