make reset work for speechdispatcher

This commit is contained in:
chrys 2019-02-26 20:42:40 +01:00
parent 05c9aafbfd
commit 97e70f1ef8
2 changed files with 23 additions and 14 deletions

View File

@ -8,6 +8,8 @@ from fenrirscreenreader.core import debug
class speechDriver(): class speechDriver():
def __init__(self): def __init__(self):
pass
def initialize(self, environment):
self._isInitialized = False self._isInitialized = False
self.language = None self.language = None
self.voice = None self.voice = None
@ -15,10 +17,8 @@ class speechDriver():
self.pitch = None self.pitch = None
self.rate = None self.rate = None
self.volume = None self.volume = None
def initialize(self, environment):
self.env = environment self.env = environment
self._isInitialized = True self._isInitialized = True
def shutdown(self): def shutdown(self):
if self._isInitialized: if self._isInitialized:
self.cancel() self.cancel()

View File

@ -15,6 +15,10 @@ class driver(speechDriver):
def initialize(self, environment): def initialize(self, environment):
self._sd = None self._sd = None
self.env = environment self.env = environment
self._isInitialized = False
self.language = ''
self.voice = ''
self.module = ''
try: try:
import speechd import speechd
self._sd = speechd.SSIPClient('fenrir') self._sd = speechd.SSIPClient('fenrir')
@ -29,7 +33,7 @@ class driver(speechDriver):
self.cancel() self.cancel()
try: try:
self._sd.close() self._sd.close()
except: except Exception as e:
pass pass
self._isInitialized = False self._isInitialized = False
@ -44,17 +48,20 @@ class driver(speechDriver):
return return
try: try:
self._sd.set_output_module(self.module) if 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: try:
self._sd.set_language(self.language) if self.language != '':
self._sd.set_language(self.language)
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver set_language:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver set_language:' + str(e),debug.debugLevel.ERROR)
try: try:
self._sd.set_synthesis_voice(self.voice) if self.voice != '':
self._sd.set_synthesis_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)
@ -71,7 +78,9 @@ class driver(speechDriver):
def cancel(self): def cancel(self):
if not self._isInitialized: if not self._isInitialized:
return self.initialize(self.env)
if not self._isInitialized:
return
try: try:
self._sd.cancel() self._sd.cancel()
except Exception as e: except Exception as e: