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,14 +17,12 @@ 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()
self._isInitialized = False self._isInitialized = False
def speak(self,text, queueable=True): def speak(self,text, queueable=True):
if not self._isInitialized: if not self._isInitialized:
@ -32,11 +32,11 @@ class speechDriver():
def cancel(self): def cancel(self):
if not self._isInitialized: if not self._isInitialized:
return return
def setCallback(self, callback): def setCallback(self, callback):
if not self._isInitialized: if not self._isInitialized:
return return
if not callback: if not callback:
return return
@ -48,7 +48,7 @@ class speechDriver():
if not self._isInitialized: if not self._isInitialized:
return return
if voice == '': if voice == '':
return return
self.voice = voice self.voice = voice
def setPitch(self, pitch): def setPitch(self, pitch):
@ -77,7 +77,7 @@ class speechDriver():
if not isinstance(module, str): if not isinstance(module, str):
return return
if module == '': if module == '':
return return
self.module = module self.module = module
def reset(self): def reset(self):
self.shutdown() self.shutdown()
@ -88,7 +88,7 @@ class speechDriver():
if not isinstance(language, str): if not isinstance(language, str):
return return
if language == '': if language == '':
return return
self.language = language self.language = language
def setVolume(self, volume): def setVolume(self, volume):
if not self._isInitialized: if not self._isInitialized:

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: