소스 검색

fix encoding

nico 8 년 전
부모
커밋
16fabbe575
4개의 변경된 파일28개의 추가작업 그리고 6개의 파일을 삭제
  1. 2 1
      core/Cache.py
  2. 4 1
      core/NeuronModule.py
  3. 20 3
      core/ShellGui.py
  4. 2 1
      tts/voxygen/voxygen.py

+ 2 - 1
core/Cache.py

@@ -23,7 +23,8 @@ class Cache:
 
     def get_audio_file_cache_path(self, words, voice, language):
         # fix UnicodeEncodeError: 'ascii' codec can't encode character X in position Y
-        words = words.encode('utf-8')
+        if isinstance(words, unicode):
+            words = words.encode('utf-8')
         md5 = hashlib.md5(words).hexdigest()
         filename = voice + "." + md5 + "." + self._cache_extension
         cache_directory = os.path.join(self._cache_path, self._module_name, language)

+ 4 - 1
core/NeuronModule.py

@@ -1,3 +1,4 @@
+# coding: utf8
 import logging
 import os
 import random
@@ -39,7 +40,7 @@ class NeuronModule(object):
         """
         # get the child who called the class
         child_name = self.__class__.__name__
-        logger.debug("NeuronModule called from class %s with parameters: %s" % (child_name, kwargs))
+        logger.debug("NeuronModule called from class %s with parameters: %s" % (child_name, str(kwargs)))
 
         self.settings = SettingLoader.get_settings()
 
@@ -93,7 +94,9 @@ class NeuronModule(object):
             for tts_object in self.settings.ttss:
                 if tts_object.name == self.tts:
                     tts_args = tts_object.parameters
+                    logger.debug("NeuronModule: tts_args: %s" % tts_args)
 
+            logger.debug("tts_message to say: %s" % tts_message)
             # change the cache settings with the one precised for the current neuron
             if self.override_cache:
                 tts_args = self._update_cache_var(self.override_cache, tts_args)

+ 20 - 3
core/ShellGui.py

@@ -1,9 +1,15 @@
+# coding: utf8
+
 import logging
 
+import sys
+
+import signal
 from dialog import Dialog
 import locale
 
 from core import OrderListener
+from core.Utils import Utils
 from core.ConfigurationManager import SettingLoader
 from neurons import Say
 
@@ -11,6 +17,14 @@ logging.basicConfig()
 logger = logging.getLogger("jarvis")
 
 
+def signal_handler(signal, frame):
+    print "\n"
+    Utils.print_info("Ctrl+C pressed. Killing Jarvis")
+    sys.exit(0)
+
+signal.signal(signal.SIGINT, signal_handler)
+
+
 class ShellGui:
     def __init__(self):
         # get settings
@@ -91,14 +105,17 @@ class ShellGui:
                 # then go back to this menu with the same sentence
                 self.show_tts_test_menu(sentence_to_test=sentence_to_test)
 
-    def _run_tts_test(self, tag, sentence_to_test):
+    def _run_tts_test(self, tts_name, sentence_to_test):
         """
         Call the TTS
-        :param tag:
+        :param tts_name: Name of the TTS module to launch
         :param sentence_to_test:
         :return:
         """
-        Say(message=sentence_to_test, tts=tag)
+        print type(sentence_to_test)
+        sentence_to_test = sentence_to_test.encode('utf-8')
+        print type(sentence_to_test)
+        Say(message=sentence_to_test, tts=tts_name)
 
     @staticmethod
     def _get_choices_tuple_from_list(list_to_convert):

+ 2 - 1
tts/voxygen/voxygen.py

@@ -53,7 +53,8 @@ class Voxygen(TTS):
         if not cache or not os.path.exists(file_path) or FileManager.file_is_empty(file_path):
             payload = {
                 "method": "redirect",
-                "text": words.encode('utf8'),
+                # "text": words.encode('utf8'),
+                "text": words,
                 "voice": voice
             }