implement sd driver

This commit is contained in:
chrys 2016-07-06 00:32:06 +02:00
parent eef85bafa9
commit 5c31ab691b
5 changed files with 72 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import hashlib
import difflib
import textwrap
import speech.es as es
import speech.sd as sd
runtime = {
'running':True,
@ -22,8 +23,8 @@ runtime = {
'newContentBytes': b'',
'newContentText': '',
'newContentAttrib': b'',
'speechDriverString':'es',
'speechDriver': es.speech()
'speechDriverString':'sd',
'speechDriver': sd.speech()
}
while(runtime['running']):
@ -46,7 +47,7 @@ while(runtime['running']):
# changes on the screen
if runtime['oldContentBytes'] != runtime['newContentBytes']:
if len(runtime['delta']) < 3:
runtime['speechDriver'].stop()
runtime['speechDriver'].cancel()
print("tty3 changed")
diff = difflib.ndiff(runtime['oldContentText'], runtime['newContentText'])

Binary file not shown.

Binary file not shown.

View File

@ -17,11 +17,11 @@ class speech():
def speak(self,text, queueable=True):
if not self.isInitialized:
return False
if queueable == False: self.stop()
if queueable == False: self.cancel()
self.es.synth(text)
return True
def stop(self):
def cancel(self):
if not self.isInitialized:
return False
self.es.cancel()
@ -46,4 +46,5 @@ class speech():
if not self.isInitialized:
return False
return es.set_parameter(espeak.Parameter.Rate, speed)
def shutdown(self):
pass

View File

@ -0,0 +1,64 @@
#!/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 shutdown(self):
self.cancel()
self.sd.close()