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

View File

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