From 65b7b8d81acb893e477b2954cbdb579e4d6a05df Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 16 Jan 2017 23:26:00 +0100 Subject: [PATCH] rework speech drivers --- src/fenrir/speechDriver/dummy.py | 25 +++++----------- src/fenrir/speechDriver/espeak.py | 22 +++++++------- src/fenrir/speechDriver/speechd.py | 47 ++++++++++++++---------------- 3 files changed, 40 insertions(+), 54 deletions(-) diff --git a/src/fenrir/speechDriver/dummy.py b/src/fenrir/speechDriver/dummy.py index 085a07d0..0e75210a 100644 --- a/src/fenrir/speechDriver/dummy.py +++ b/src/fenrir/speechDriver/dummy.py @@ -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 diff --git a/src/fenrir/speechDriver/espeak.py b/src/fenrir/speechDriver/espeak.py index 71f933a7..5767c3e5 100644 --- a/src/fenrir/speechDriver/espeak.py +++ b/src/fenrir/speechDriver/espeak.py @@ -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)) diff --git a/src/fenrir/speechDriver/speechd.py b/src/fenrir/speechDriver/speechd.py index 8a7ef856..0d1d06e7 100644 --- a/src/fenrir/speechDriver/speechd.py +++ b/src/fenrir/speechDriver/speechd.py @@ -29,81 +29,78 @@ class driver(): return self._isInitialized = False self.cancel() - self._sd.close() - return + try: + self._sd.close() + 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 - self._sd.set_volume(int(-100 + volume * 200)) - + return + try: + self._sd.set_volume(int(-100 + volume * 200)) + except: + pass