소스 검색

remove print, replace by print from utils or log

nico 8 년 전
부모
커밋
1a7b6704e4
6개의 변경된 파일30개의 추가작업 그리고 20개의 파일을 삭제
  1. 0 1
      core/MainController.py
  2. 6 7
      core/NeuronModule.py
  3. 8 2
      core/NeuroneLauncher.py
  4. 8 4
      core/ShellGui.py
  5. 6 4
      stt/google/Google.py
  6. 2 2
      tts/pico2wave/pico2wave.py

+ 0 - 1
core/MainController.py

@@ -41,7 +41,6 @@ class MainController:
         """
         # pause the snowboy process
         self.pause_jarvis_trigger()
-        print "Start listening for order"
         random_answers = self.conf["random_wake_up_answers"]
         Say(message=random_answers)
         self.order_listener.load_stt_plugin()

+ 6 - 7
core/NeuronModule.py

@@ -73,15 +73,15 @@ class NeuronModule(object):
         tts_message = None
 
         if isinstance(message, str):
-            print "message is string"
+            logger.debug("message is string")
             tts_message = message
 
         if isinstance(message, list):
-            print "message is list"
+            logger.debug("message is list")
             tts_message = self._get_message_from_list(message)
 
         if isinstance(message, dict):
-            print "message is dict"
+            logger.debug("message is dict")
             tts_message = self._get_message_from_dict(message)
 
         if message is not None:
@@ -155,8 +155,7 @@ class NeuronModule(object):
 
     @staticmethod
     def _update_cache_var(new_override_cache, args_list):
-        print "args for TTS plugin before update: %s" % str(args_list)
+        logger.debug("args for TTS plugin before update: %s" % str(args_list))
         args_list["cache"] = new_override_cache
-
-        print "args for TTS plugin after update: %s" % str(args_list)
-        return args_list
+        logger.debug("args for TTS plugin after update: %s" % str(args_list))
+        return args_list

+ 8 - 2
core/NeuroneLauncher.py

@@ -1,3 +1,9 @@
+import logging
+
+logging.basicConfig()
+logger = logging.getLogger("jarvis")
+
+
 class NeuroneNotFoundError(Exception):
     pass
 
@@ -9,12 +15,12 @@ def _run_plugin(plugin, parameters=None):
     :param parameters: Parameter of the module
     :return:
     """
-    print "Run plugin %s with parameter %s" % (plugin, parameters)
+    logger.debug("Run plugin %s with parameter %s" % (plugin, parameters))
     mod = __import__('neurons', fromlist=[plugin])
     try:
         klass = getattr(mod, plugin)
     except AttributeError:
-        print "Error: No module named %s " % plugin
+        logger.debug("Error: No module named %s " % plugin)
         raise NeuroneNotFoundError
 
     if klass is not None:

+ 8 - 4
core/ShellGui.py

@@ -1,3 +1,5 @@
+import logging
+
 from dialog import Dialog
 import locale
 
@@ -5,6 +7,9 @@ from core import ConfigurationManager
 from core import OrderListener
 from neurons import Say
 
+logging.basicConfig()
+logger = logging.getLogger("jarvis")
+
 
 class ShellGui:
     def __init__(self):
@@ -38,7 +43,7 @@ class ShellGui:
     def show_stt_test_menu(self):
         # we get STT from settings
         stt_list = ConfigurationManager.get_stt_list()
-        print stt_list
+        logger.debug("Loaded stt list: %s" % str(stt_list))
         choices = self._get_choices_tuple_from_list(stt_list)
 
         code, tag = self.d.menu("Select the STT to test:",
@@ -48,7 +53,6 @@ class ShellGui:
             self.show_main_menu()
 
         if code == self.d.OK:
-            print tag
             self.d.infobox("Please talk now")
             order_listener = OrderListener(callback=self.callback_stt, stt=str(tag))
             order_listener.load_stt_plugin()
@@ -108,11 +112,11 @@ class ShellGui:
         for el in list_to_convert:
             try:
                 for name, settings in el.iteritems():
-                    print name
-                    print settings
                     tup = (str(name), str(settings))
                     choices.append(tup)
+                    logger.debug("Add stt to the list: %s with parameters: %s" % (str(el), str(settings)))
             except AttributeError:
+                logger.debug("Add stt to the list: %s" % str(el))
                 # sometime there is no settings for the STT key
                 tup = (str(el), str("No settings"))
                 choices.append(tup)

+ 6 - 4
stt/google/Google.py

@@ -1,4 +1,6 @@
 import speech_recognition as sr
+
+from core import Utils
 from core.OrderListener import OrderListener
 
 
@@ -23,7 +25,7 @@ class Google(OrderListener):
         with sr.Microphone() as source:
             # listen for 1 second to calibrate the energy threshold for ambient noise levels
             r.adjust_for_ambient_noise(source)
-            print("Say something!")
+            Utils.print_info("Say something!")
             audio = r.listen(source)
 
         # recognize speech using Google Speech Recognition
@@ -37,13 +39,13 @@ class Google(OrderListener):
             show_all = kwargs.get('show_all', False)
 
             captured_audio = r.recognize_google(audio, key=key, language=language, show_all=show_all)
-            print "Google Speech Recognition thinks you said %s" % captured_audio
+            Utils.print_success("Google Speech Recognition thinks you said %s" % captured_audio)
             self._analyse_audio(captured_audio)
 
         except sr.UnknownValueError:
-            print("Google Speech Recognition could not understand audio")
+            Utils.print_warning("Google Speech Recognition could not understand audio")
         except sr.RequestError as e:
-            print("Could not request results from Google Speech Recognition service; {0}".format(e))
+            Utils.print_danger("Could not request results from Google Speech Recognition service; {0}".format(e))
 
     def _analyse_audio(self, audio):
         # if self.main_controller is not None:

+ 2 - 2
tts/pico2wave/pico2wave.py

@@ -26,12 +26,12 @@ class Pico2wave(TTS):
         self.play_audio(file_path, cache=cache)
 
     def get_voice(self, language):
-        print "asked lang: %s" % language
+        logger.debug("Pico2wave asked lang: %s" % language)
 
         if language in self.PICO2WAVE_LANGUAGES:
             return self.PICO2WAVE_LANGUAGES[language]
 
-        logger.warn("Cannot find language matching language:  %s replace by default voice: %s", language, self.PICO2WAVE_LANGUAGES_DEFAULT)
+        logger.debug("Cannot find language matching language:  %s replace by default voice: %s", language, self.PICO2WAVE_LANGUAGES_DEFAULT)
         return self.PICO2WAVE_LANGUAGES_DEFAULT
 
     @staticmethod