Procházet zdrojové kódy

add file destination for logging

Martin před 9 roky
rodič
revize
320719c2d5

+ 18 - 5
voice_control/conf.py

@@ -2,21 +2,34 @@ import os
 
 _VC_DIR = os.path.dirname(os.path.abspath(__file__))
 
+#########################################################################
+# INPUT/OUTPUT SERVICES
+#########################################################################
+
+# Voice input
+SPEECH_INPUT_ENABLED = True
+SNOWBOY_HOTWORD_MODEL = 'resources/snowboy/alexa.umdl'
+SPEECH_RECOGNITION_MIN_ENERGY_LEVEL = 400
+
 # Audio output
 SOUND_OUTPUT_ENABLED = False
 CLIPS_FOLDER = os.path.join(_VC_DIR, '..', 'resources', 'clips')
 
-# Voice input
-SPEECH_INPUT_ENABLED = False
+# Slack I/O
+SLACK_BOT_API_KEY = None # 'xoxb-124589937168-ljmRwQODWQ2R1d7eIs99hAc1'
+
+# Logging
+LOGFILE = '/tmp/voice_recognition.log'
+
+#########################################################################
+# PROCESSING SERVICES
+#########################################################################
 
 # Music
 MUSIC_FOLDERS = [
     #'/mnt/nas/music/albums'
 ] 
 
-# Slack I/O
-SLACK_BOT_API_KEY = None # 'xoxb-124589937168-ljmRwQODWQ2R1d7eIs99hAc1'
-
 # Mailgun
 MAILGUN_API_URL = 'https://api.mailgun.net/v3/mg.gerner.co'
 MAILGUN_API_KEY = 'key-80245476ae35aa626d782556419280f9'

+ 7 - 4
voice_control/main.py

@@ -5,6 +5,7 @@ import input_sources
 import output
 import services
 import util.curses_util
+import conf
 
 _INTERRUPTED = False
 
@@ -17,9 +18,9 @@ def _interrupt_callback():
     return _INTERRUPTED
 
 def _init_logging():
-    logging.basicConfig(stream=sys.stdout)
-    logging.getLogger().setLevel(logging.INFO)
-    signal.signal(signal.SIGINT, _signal_handler)
+    if conf.LOGFILE is not None:
+        logging.basicConfig(filename=conf.LOGFILE)
+        logging.getLogger().setLevel(logging.DEBUG)
 
 def cb():
     print 'CB!'
@@ -36,12 +37,14 @@ def test():
 
 def _run(cclient):
     _init_logging()
+    signal.signal(signal.SIGINT, _signal_handler)
+
     output.init_services(cclient)
     input_sources.launch_input_sources(cclient)
     services.launch_services(cclient, _interrupt_callback)
 
 if __name__ == "__main__":
-    if True:
+    if False:
         test()
 
     else:

+ 3 - 0
voice_control/output/__init__.py

@@ -16,6 +16,9 @@ def init_services(cclient):
     if conf.SLACK_BOT_API_KEY:
         import slack_bot
         SERVICES.append(slack_bot.SlackBot())
+    if conf.LOGFILE:
+        import vc_logging
+        SERVICES.append(vc_logging.Logging())
 
 def success(msg='OK.'):
     for service in SERVICES:

+ 21 - 0
voice_control/output/vc_logging.py

@@ -0,0 +1,21 @@
+import logging
+import base
+
+class Logging(base.Base):
+    def failure(self, msg):
+        logging.info(msg)
+        
+    def tts(self, msg):
+        logging.info(msg)
+    
+    def text(self, msg):
+        logging.info(msg)
+    
+    def debug(self, msg):
+        logging.info(msg)
+    
+    def cancelled(self, msg):
+        logging.info(msg)
+    
+    def success(self, msg):
+        logging.info(msg)