make propertys work inital for genericSpeechDriver, add settings

This commit is contained in:
chrys
2017-03-02 20:20:15 +01:00
parent 9ba8c627df
commit b5ec64bb13
6 changed files with 122 additions and 224 deletions

View File

@ -26,6 +26,13 @@ settings = {
'voice': '',
'language': 'english-us',
'autoReadIncoming': True,
'genericSpeechCommand':'espeak -a fenrirVolume -s fenrirRate -p fenrirPitch -v fenrirVoice "fenrirText"',
'fenrirMinVolume':0,
'fenrirMaxVolume':200,
'fenrirMinPitch':0,
'fenrirMaxPitch':99,
'fenrirMinRate':80,
'fenrirMaxRate':450,
},
'braille':{
'enabled': False,

View File

@ -30,14 +30,22 @@ class driver():
self.module = None
self.language = None
self.voice = None
def initialize(self, environment):
self._isInitialized = True
self.env = environment
self.speechCommand = ''
#self.speechCommand = self.env['runtime']['settingsManager'].getSetting('speech', 'genericSpeechCommand')
def initialize(self, environment):
self.env = environment
self.minVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinVolume')
self.maxVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxVolume')
self.minPitch = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinPitch')
self.maxPitch = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxPitch')
self.minRate = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinRate')
self.maxRate = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxRate')
self.speechCommand = self.env['runtime']['settingsManager'].getSetting('speech', 'genericSpeechCommand')
if self.speechCommand == '':
self.speechCommand = 'spd-say "fenrirText"'
#'espeak -a fenrirVolume -s fenrirRate -p fenrirPitch -v fenrirVoice "fenrirText"'
self.speechCommand = 'espeak -a fenrirVolume -s fenrirRate -p fenrirPitch -v fenrirVoice "fenrirText"'
if False: #for debugging overwrite here
self.speechCommand = 'spd-say --wait "fenrirText"'
self._isInitialized = True
if self._isInitialized:
self.speechThread.start()
def shutdown(self):
@ -50,13 +58,7 @@ class driver():
if not self._isInitialized:
return
if not queueable:
self.cancel()
self.volume = '200'
self.rate = '200'
self.pitch = '200'
self.module = ''
self.language = ''
self.voice = 'de'
self.cancel()
utterance = {
'text': text,
'volume': self.volume,
@ -86,32 +88,32 @@ class driver():
def setVoice(self, voice):
if not self._isInitialized:
return
print('SpeechDummyDriver: setVoice:' + str(voice))
self.voice = str(voice)
def setPitch(self, pitch):
if not self._isInitialized:
return
print('SpeechDummyDriver: setPitch:' + str(pitch))
self.pitch = self.minPitch + pitch * (self.maxPitch - self.minPitch )
def setRate(self, rate):
if not self._isInitialized:
return
print('SpeechDummyDriver: setRate:' + str(rate))
self.rate = self.minRate + rate * (self.maxRate - self.minRate )
def setModule(self, module):
if not self._isInitialized:
return
print('SpeechDummyDriver: setModule:' + str(module))
self.module = str(module)
def setLanguage(self, language):
if not self._isInitialized:
return
print('SpeechDummyDriver: setLanguage:' + str(language))
self.language = str(language)
def setVolume(self, volume):
if not self._isInitialized:
return
print('SpeechDummyDriver: setVolume:' + str(volume))
self.volume = self.minVolume + volume * (self.maxVolume - self.minVolume )
def worker(self):
while True:
@ -121,31 +123,32 @@ class driver():
return
elif not isinstance(utterance, dict):
continue
print(utterance)
for key, item in utterance.items():
for key in ['volume','module','language','voice','pitch','rate','text']:
if not key in utterance:
utterance[key] = ''
if not utterance[key]:
utterance[key] = ''
print(utterance)
popenSpeechCommand = self.speechCommand
popenSpeechCommand = popenSpeechCommand.replace('fenrirVolume', str(utterance['volume'] ))
popenSpeechCommand = popenSpeechCommand.replace('fenrirModule', str(utterance['module']))
popenSpeechCommand = popenSpeechCommand.replace('fenrirLanguage', str(utterance['language']))
popenSpeechCommand = popenSpeechCommand.replace('fenrirVoice', str(utterance['voice']))
popenSpeechCommand = popenSpeechCommand.replace('fenrirPitch', str(utterance['pitch']))
popenSpeechCommand = popenSpeechCommand.replace('fenrirRate', str(utterance['rate'] ))
popenSpeechCommand = popenSpeechCommand.replace('fenrirText', str(utterance['text'] ))
self.proc = Popen(popenSpeechCommand, shell=True)
try:
self.proc = Popen(popenSpeechCommand , stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = p.communicate()
screenEncoding = self.env['runtime']['settingsManager'].getSetting('screen', 'encoding')
stderr = stderr.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
stdout = stdout.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
if stderr != '':
print('err' + stderr)
if stdout != '':
print('out' + stdout)
except Exception as e:
print('except' + str(e))
popenSpeechCommand = popenSpeechCommand.replace('fenrirVolume', str(utterance['volume'] ).replace('"',''))
popenSpeechCommand = popenSpeechCommand.replace('fenrirModule', str(utterance['module']).replace('"',''))
popenSpeechCommand = popenSpeechCommand.replace('fenrirLanguage', str(utterance['language']).replace('"',''))
popenSpeechCommand = popenSpeechCommand.replace('fenrirVoice', str(utterance['voice']).replace('"',''))
popenSpeechCommand = popenSpeechCommand.replace('fenrirPitch', str(utterance['pitch']).replace('"',''))
popenSpeechCommand = popenSpeechCommand.replace('fenrirRate', str(utterance['rate']).replace('"',''))
popenSpeechCommand = popenSpeechCommand.replace('fenrirText', str(utterance['text']).replace('"','').replace('\n',''))
try:
self.proc = Popen(popenSpeechCommand , stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = self.proc.communicate()
screenEncoding = self.env['runtime']['settingsManager'].getSetting('screen', 'encoding')
stderr = stderr.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
stdout = stdout.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
if stderr != '':
print('err' + stderr)
if stdout != '':
print('out' + stdout)
except Exception as e:
print('except' + str(e))