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 return False
if not queueable: if not queueable:
self.cancel() self.cancel()
return True
def cancel(self): def cancel(self):
if not self._isInitialized: if not self._isInitialized:
return False return
return True
def setCallback(self, callback): def setCallback(self, callback):
pass pass
def clear_buffer(self): def clear_buffer(self):
if not self._isInitialized: if not self._isInitialized:
return False return
return True
def setVoice(self, voice): def setVoice(self, voice):
if not self._isInitialized: if not self._isInitialized:
return False return
return True
def setPitch(self, pitch): def setPitch(self, pitch):
if not self._isInitialized: if not self._isInitialized:
return False return
return True
def setRate(self, rate): def setRate(self, rate):
if not self._isInitialized: if not self._isInitialized:
return False return
return True
def setModule(self, module): def setModule(self, module):
if not self._isInitialized: if not self._isInitialized:
return False return
return True
def setLanguage(self, language): def setLanguage(self, language):
if not self._isInitialized: if not self._isInitialized:
return False return
return True
def setVolume(self, volume): def setVolume(self, volume):
if not self._isInitialized: if not self._isInitialized:
return False return
return True

View File

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

View File

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