fix speechd

This commit is contained in:
chrys 2019-02-15 18:43:04 +01:00
parent 276c33c834
commit 876e8fa563

View File

@ -21,8 +21,8 @@ class driver(speechDriver):
self._punct = speechd.PunctuationMode() self._punct = speechd.PunctuationMode()
self._isInitialized = True self._isInitialized = True
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver initialize:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver initialize:' + str(e),debug.debugLevel.ERROR)
def shutdown(self): def shutdown(self):
if not self._isInitialized: if not self._isInitialized:
return return
@ -31,33 +31,46 @@ class driver(speechDriver):
self._sd.close() self._sd.close()
except: except:
pass pass
self._isInitialized = False self._isInitialized = False
def speak(self,text, queueable=True): def speak(self,text, queueable=True):
if not queueable: if not queueable:
self.cancel() self.cancel()
if not self._isInitialized: if not self._isInitialized:
self.initialize(self.env) self.initialize(self.env)
if not self._isInitialized: if not self._isInitialized:
return return
try: try:
self._sd.set_output_module(self.module) self._sd.set_output_module(self.module)
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setModule:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver setModule:' + str(e),debug.debugLevel.ERROR)
try:
if self.language != '':
self._sd.set_language(self.language)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver set_language:' + str(e),debug.debugLevel.ERROR)
self._isInitialized = False
try: try:
if self.voice: if self.voice:
if self.voice != '': if self.voice != '':
self._sd.set_voice(self.voice) self._sd.set_voice(self.voice)
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setVoice:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver setVoice:' + str(e),debug.debugLevel.ERROR)
try: try:
if self.language != '': self._sd.set_punctuation(self._punct.NONE)
self._sd.set_synthesis_voice(self.language)
self._sd.set_punctuation(self._punct.NONE)
self._sd.speak(text)
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver speak:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver set_punctuation:' + str(e),debug.debugLevel.ERROR)
self._isInitialized = False
try:
self._sd.speak(text)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver speak:' + str(e),debug.debugLevel.ERROR)
self._isInitialized = False self._isInitialized = False
def cancel(self): def cancel(self):
@ -66,16 +79,16 @@ class driver(speechDriver):
try: try:
self._sd.cancel() self._sd.cancel()
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver cancel:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver cancel:' + str(e),debug.debugLevel.ERROR)
self._isInitialized = False self._isInitialized = False
def setPitch(self, pitch): def setPitch(self, pitch):
if not self._isInitialized: if not self._isInitialized:
return return
try: try:
self._sd.set_pitch(int(-100 + pitch * 200)) self._sd.set_pitch(int(-100 + pitch * 200))
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setPitch:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver setPitch:' + str(e),debug.debugLevel.ERROR)
def setRate(self, rate): def setRate(self, rate):
if not self._isInitialized: if not self._isInitialized:
@ -83,12 +96,12 @@ class driver(speechDriver):
try: try:
self._sd.set_rate(int(-100 + rate * 200)) self._sd.set_rate(int(-100 + rate * 200))
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setRate:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver setRate:' + str(e),debug.debugLevel.ERROR)
def setVolume(self, volume): def setVolume(self, volume):
if not self._isInitialized: if not self._isInitialized:
return return
try: try:
self._sd.set_volume(int(-100 + volume * 200)) self._sd.set_volume(int(-100 + volume * 200))
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setVolume:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver setVolume:' + str(e),debug.debugLevel.ERROR)