implement attribute parsing and cursor
This commit is contained in:
parent
f0f3969366
commit
17a9901ecb
@ -11,11 +11,14 @@ import speech.es as es
|
|||||||
|
|
||||||
runtime = {
|
runtime = {
|
||||||
'columns': 0,
|
'columns': 0,
|
||||||
|
'lines': 0,
|
||||||
'screenDriver': '/dev/vcsa3',
|
'screenDriver': '/dev/vcsa3',
|
||||||
'delta': '',
|
'delta': '',
|
||||||
|
'oldCursor':{'x':0,'y':0},
|
||||||
'oldContentBytes': b'',
|
'oldContentBytes': b'',
|
||||||
'oldContentText': '',
|
'oldContentText': '',
|
||||||
'oldContentAttrib': b'',
|
'oldContentAttrib': b'',
|
||||||
|
'newCursor':{'x':0,'y':0},
|
||||||
'newContentBytes': b'',
|
'newContentBytes': b'',
|
||||||
'newContentText': '',
|
'newContentText': '',
|
||||||
'newContentAttrib': b'',
|
'newContentAttrib': b'',
|
||||||
@ -24,15 +27,23 @@ runtime = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while(True):
|
while(True):
|
||||||
|
# read screen
|
||||||
vcsa = open(runtime['screenDriver'],'rb')
|
vcsa = open(runtime['screenDriver'],'rb')
|
||||||
runtime['newContentBytes'] = vcsa.read()
|
runtime['newContentBytes'] = vcsa.read()
|
||||||
vcsa.close()
|
vcsa.close()
|
||||||
|
|
||||||
|
# get metadata like cursor or screensize
|
||||||
|
runtime['lines'] = int( runtime['newContentBytes'][0])
|
||||||
runtime['columns'] = int( runtime['newContentBytes'][1])
|
runtime['columns'] = int( runtime['newContentBytes'][1])
|
||||||
runtime['newContentText'] = str(runtime['newContentBytes'][::2].decode('cp1252').encode('utf-8'))[7:]
|
runtime['newCursor']['x'] = int( runtime['newContentBytes'][2])
|
||||||
runtime['newContentAttrib'] = runtime['newContentBytes'][1::2][7:]
|
runtime['newCursor']['y'] = int( runtime['newContentBytes'][3])
|
||||||
print(runtime['newContentBytes'][9])
|
|
||||||
#runtime['newContentString'] = str(runtime['newContentBytes'].decode('cp1252').encode('utf-8'))
|
# 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']))
|
runtime['newContentText'] = '\n'.join(textwrap.wrap(runtime['newContentText'], runtime['columns']))
|
||||||
|
|
||||||
|
# changes on the screen
|
||||||
if runtime['oldContentBytes'] != runtime['newContentBytes']:
|
if runtime['oldContentBytes'] != runtime['newContentBytes']:
|
||||||
runtime['speechDriver'].stop()
|
runtime['speechDriver'].stop()
|
||||||
print("tty3 changed")
|
print("tty3 changed")
|
||||||
@ -40,10 +51,12 @@ while(True):
|
|||||||
diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText'])
|
diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText'])
|
||||||
runtime['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
|
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['oldContentBytes'] = runtime['newContentBytes']
|
||||||
runtime['oldContentText'] = runtime['newContentText']
|
runtime['oldContentText'] = runtime['newContentText']
|
||||||
runtime['oldContentTextAttrib'] = runtime['newContentAttrib']
|
runtime['oldContentTextAttrib'] = runtime['newContentAttrib']
|
||||||
|
runtime['oldCursor']['x'] = runtime['newCursor']['x']
|
||||||
|
runtime['oldCursor']['y'] = runtime['newCursor']['y']
|
||||||
|
|
||||||
|
@ -6,20 +6,44 @@ class speech():
|
|||||||
def __init__(self, ):
|
def __init__(self, ):
|
||||||
self.es = None
|
self.es = None
|
||||||
self.isInitialized = False
|
self.isInitialized = False
|
||||||
# try:
|
try:
|
||||||
from espeak import espeak
|
from espeak import espeak
|
||||||
self.es = espeak
|
self.es = espeak
|
||||||
self.isInitialized = True
|
self.isInitialized = True
|
||||||
# except:
|
except:
|
||||||
# self.initialized = False
|
self.initialized = False
|
||||||
|
|
||||||
|
|
||||||
def speak(self,text, queueable=True):
|
def speak(self,text, queueable=True):
|
||||||
|
if not self.isInitialized:
|
||||||
|
return False
|
||||||
if queueable == False: self.stop()
|
if queueable == False: self.stop()
|
||||||
self.es.synth(text)
|
self.es.synth(text)
|
||||||
|
return True
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
if not self.isInitialized:
|
||||||
|
return False
|
||||||
self.es.cancel()
|
self.es.cancel()
|
||||||
|
return True
|
||||||
|
|
||||||
def clear_buffer(self):
|
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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user