rework speech drivers

This commit is contained in:
chrys 2017-01-16 23:26:00 +01:00
parent 15d3fffeac
commit 65b7b8d81a
3 changed files with 40 additions and 54 deletions

View File

@ -21,47 +21,38 @@ class driver():
return False
if not queueable:
self.cancel()
return True
def cancel(self):
if not self._isInitialized:
return False
return True
return
def setCallback(self, callback):
pass
def clear_buffer(self):
if not self._isInitialized:
return False
return True
return
def setVoice(self, voice):
if not self._isInitialized:
return False
return True
return
def setPitch(self, pitch):
if not self._isInitialized:
return False
return True
return
def setRate(self, rate):
if not self._isInitialized:
return False
return True
return
def setModule(self, module):
if not self._isInitialized:
return False
return True
return
def setLanguage(self, language):
if not self._isInitialized:
return False
return True
return
def setVolume(self, volume):
if not self._isInitialized:
return False
return True
return

View File

@ -27,11 +27,10 @@ class driver():
def speak(self,text, interrupt=True):
if not self._isInitialized:
return False
return
if not interrupt:
self.cancel()
self._es.synth(text)
return True
def cancel(self):
if not self._isInitialized:
@ -44,38 +43,37 @@ class driver():
def clear_buffer(self):
if not self._isInitialized:
return False
return True
return
def setVoice(self, voice):
if not self._isInitialized:
return False
return
if voice =='':
return False
return
return self._es.set_voice(voice)
def setPitch(self, pitch):
if not self._isInitialized:
return False
return
return self._es.set_parameter(self._es.Parameter().Pitch, int(pitch * 99))
def setRate(self, rate):
if not self._isInitialized:
return False
return
return self._es.set_parameter(self._es.Parameter().Rate, int(rate * 500 + 100))
def setModule(self, module):
if not self._isInitialized:
return False
return
def setLanguage(self, language):
if not self._isInitialized:
return False
return
if language =='':
return False
return
return self._es.set_voice(language)
def setVolume(self, volume):
if not self._isInitialized:
return False
return
return self._es.set_parameter(self._es.Parameter().Volume, int(volume * 200))

View File

@ -29,81 +29,78 @@ class driver():
return
self._isInitialized = False
self.cancel()
try:
self._sd.close()
return
except:
pass
def speak(self,text, queueable=True):
if not self._isInitialized:
self.initialize(self.env)
if not self._isInitialized:
return False
if queueable == False: self.cancel()
try:
if queueable == False: self.cancel()
self._sd.set_synthesis_voice(self._language)
self._sd.set_punctuation(self._punct.NONE)
self._sd.speak(text)
except Exception as e:
self._isInitialized = False
self._sd.speak(text)
return True
def cancel(self):
if not self._isInitialized:
return False
return
self._sd.cancel()
return True
def setCallback(self, callback):
pass
def clear_buffer(self):
if not self._isInitialized:
return False
return True
return
def setVoice(self, voice):
if not self._isInitialized:
return False
return
try:
if voice != '':
self._sd.set_voice(voice)
return True
except:
return False
pass
def setPitch(self, pitch):
if not self._isInitialized:
return False
return
try:
self._sd.set_pitch(int(-100 + pitch * 200))
return True
except:
return False
pass
def setRate(self, rate):
if not self._isInitialized:
return False
return
try:
self._sd.set_rate(int(-100 + rate * 200))
return True
except:
return False
pass
def setModule(self, module):
if not self._isInitialized:
return False
return
try:
self._sd.set_output_module(module)
return True
except:
return False
pass
def setLanguage(self, language):
if not self._isInitialized:
return False
return
self._language = language
def setVolume(self, volume):
if not self._isInitialized:
return False
return
try:
self._sd.set_volume(int(-100 + volume * 200))
except:
pass