Browse Source

Check content-type tts web return

Unknown 8 years ago
parent
commit
5d7bba1f04
1 changed files with 4 additions and 2 deletions
  1. 4 2
      tts/voxygen/voxygen.py

+ 4 - 2
tts/voxygen/voxygen.py

@@ -19,6 +19,7 @@ VOXYGEN_LANGUAGES = dict(
 VOXYGEN_VOICE_DEFAULT = "Michel"
 VOXYGEN_LANGUAGES_DEFAULT = "default"
 VOXYGEN_URL = "https://www.voxygen.fr/sites/all/modules/voxygen_voices/assets/proxy/index.php"
+VOXYGEN_CONTENT_TYPE = "audio/mpeg"
 
 CACHE_PATH = "/tmp/jarvis/tts/voxygen"
 CACHE_EXTENSION = ".tts"
@@ -66,10 +67,11 @@ def get_audio(voice, text, file_path, cache):
         }
 
         r = requests.get(VOXYGEN_URL, params=payload, stream=True)
-        logging.debug("Trying to get url: %s response code: %s", r.url, r.status_code)
+        content_type = r.headers['Content-Type']
+        logging.debug("Trying to get url: %s response code: %s and content-type: %s", r.url, r.status_code, content_type)
 
         try:
-            if r.status_code == 200:
+            if r.status_code == requests.codes.ok and content_type == VOXYGEN_CONTENT_TYPE:
                 write_in_file(file_path, r.content)
                 return True
             else: