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