Procházet zdrojové kódy

clean up output method params a bit

Martin před 9 roky
rodič
revize
f72fdfad60

+ 12 - 12
voice_control/output/__init__.py

@@ -17,26 +17,26 @@ def init_services(cclient):
         import slack_bot
         SERVICES.append(slack_bot.SlackBot())
 
-def success():
+def success(msg='OK.'):
     for service in SERVICES:
-        service.success()
+        service.success(msg)
 
-def failure(s=None):
+def failure(msg='Failed.'):
     for service in SERVICES:
-        service.failure(s)
+        service.failure(msg)
 
-def cancelled():
+def cancelled(msg='Cancelled.'):
     for service in SERVICES:
-        service.cancelled()
+        service.cancelled(msg)
 
-def tts(s):
+def tts(msg):
     for service in SERVICES:
-        service.tts(s)
+        service.tts(msg)
 
-def text(s):
+def text(msg):
     for service in SERVICES:
-        service.text(s)
+        service.text(msg)
 
-def debug(s):
+def debug(msg):
     for service in SERVICES:
-        service.debug(s)
+        service.debug(msg)

+ 6 - 9
voice_control/output/audio_output.py

@@ -45,27 +45,24 @@ def _play_clip(clip):
     return
 
 class AudioOutput(base.Base):
-    def tts(self, text):
-        if not text:
-            return
-
-        tts_hash = hashlib.md5(text.lower()).hexdigest()
+    def tts(self, msg):
+        tts_hash = hashlib.md5(msg.lower()).hexdigest()
         cache_fname = os.path.join(TMP_DIR, tts_hash) + '.mp3'
         if os.path.isfile(cache_fname):
             _play(cache_fname, True)
             return
 
-        tts_stream = gTTS(text=text, lang='en')
+        tts_stream = gTTS(text=msg, lang='en')
         with open(cache_fname, 'w') as f:
             tts_stream.write_to_fp(f)
 
         _play(cache_fname, True)
     
-    def success(self):
+    def success(self, *_):
         _play_clip(Clips.SUCCESS)
     
     def failure(self, *_):
         _play_clip(Clips.FAILURE)
     
-    def cancelled(self):
-        self.tts('cancelled')
+    def cancelled(self, msg):
+        self.tts(msg)

+ 6 - 6
voice_control/output/base.py

@@ -1,13 +1,13 @@
 class Base(object):
-    def success(self):
+    def success(self, msg):
         pass
-    def failure(self, s=None):
+    def failure(self, msg):
         pass
-    def cancelled(self):
+    def cancelled(self, msg):
         pass
-    def tts(self, s): 
+    def tts(self, msg):
         pass
-    def text(self, s):
+    def text(self, msg):
         pass
-    def debug(self, s):
+    def debug(self, msg):
         pass

+ 12 - 15
voice_control/output/console.py

@@ -6,23 +6,20 @@ class Console(base.Base):
     def __init__(self, cclient):
         self.cclient = cclient
 
-    def failure(self, s=None):
-        if s is None:
-            self.cclient.print_str('Failed.')
-        else:
-            self.cclient.print_str(s)
+    def failure(self, msg):
+        self.cclient.print_str(msg)
         
-    def tts(self, s):
-        self.cclient.print_str(s)
+    def tts(self, msg):
+        self.cclient.print_str(msg)
     
-    def text(self, s):
-        self.cclient.print_str(s)
+    def text(self, msg):
+        self.cclient.print_str(msg)
     
-    def debug(self, s):
-        self.cclient.print_str(s)
+    def debug(self, msg):
+        self.cclient.print_str(msg)
     
-    def cancelled(self):
-        self.cclient.print_str('Cancelled.')
+    def cancelled(self, msg):
+        self.cclient.print_str(msg)
     
-    def success(self):
-        self.cclient.print_str('OK.')
+    def success(self, msg):
+        self.cclient.print_str(msg)

+ 12 - 15
voice_control/output/slack_bot.py

@@ -14,23 +14,20 @@ class SlackBot(base.Base):
             text=text
         )
 
-    def success(self):
-        self._send('Ok.')
+    def success(self, msg):
+        self._send(msg)
     
-    def failure(self, s=None):
-        if s:
-            self._send(s)
-        else:
-            self._send('Error.')
+    def failure(self, msg):
+        self._send(msg)
 
-    def cancelled(self):
-        self._send('Cancelled.')
+    def cancelled(self, msg):
+        self._send(msg)
     
-    def tts(self, s):
-        self._send(s)
+    def tts(self, msg):
+        self._send(msg)
 
-    def text(self, s):
-        self._send(s)
+    def text(self, msg):
+        self._send(msg)
 
-    def debug(self, s):
-        self._send(s)
+    def debug(self, msg):
+        self._send(msg)