|
| 1 | +#!/usr/bin/env python |
| 2 | +# coding=utf-8 |
| 3 | + |
| 4 | +""" |
| 5 | +Check whether the setup of aeneas was successful. |
| 6 | +
|
| 7 | +Requires the audio file aeneas/tools/res/audio.mp3 |
| 8 | +
|
| 9 | +Running this script makes sense only |
| 10 | +if you git-cloned the original GitHub repository |
| 11 | +and/or if you are interested in contributing to the |
| 12 | +development of aeneas. |
| 13 | +""" |
| 14 | + |
| 15 | +import os |
| 16 | +import tempfile |
| 17 | + |
| 18 | +__author__ = "Alberto Pettarin" |
| 19 | +__copyright__ = """ |
| 20 | + Copyright 2012-2013, Alberto Pettarin (www.albertopettarin.it) |
| 21 | + Copyright 2013-2015, ReadBeyond Srl (www.readbeyond.it) |
| 22 | + Copyright 2015, Alberto Pettarin (www.albertopettarin.it) |
| 23 | + """ |
| 24 | +__license__ = "GNU AGPL 3" |
| 25 | +__version__ = "1.3.2" |
| 26 | + |
| 27 | +__status__ = "Production" |
| 28 | + |
| 29 | +SETUP_COMMAND = "'python setup.py build_ext --inplace'" |
| 30 | + |
| 31 | +def on_error(msg): |
| 32 | + print "[ERRO] %s" % msg |
| 33 | + |
| 34 | +def on_info(msg): |
| 35 | + print "[INFO] %s" % msg |
| 36 | + |
| 37 | +def on_warning(msg): |
| 38 | + print "[WARN] %s" % msg |
| 39 | + |
| 40 | +def get_abs_path(rel_path): |
| 41 | + file_dir = os.path.dirname(__file__) |
| 42 | + return os.path.join(file_dir, rel_path) |
| 43 | + |
| 44 | +def step1(): |
| 45 | + on_info("Test 1/7 (import)...") |
| 46 | + try: |
| 47 | + on_info(" Trying to import package aeneas...") |
| 48 | + import aeneas |
| 49 | + on_info(" Trying to import package aeneas... succeeded.") |
| 50 | + return True |
| 51 | + except ImportError: |
| 52 | + on_error(" Unable to import package aeneas.") |
| 53 | + on_error(" Check that you have installed the following Python (2.7.x) packages:") |
| 54 | + on_error(" 1. BeautifulSoup") |
| 55 | + on_error(" 2. lxml") |
| 56 | + on_error(" 3. numpy") |
| 57 | + except: |
| 58 | + pass |
| 59 | + return False |
| 60 | + |
| 61 | +def step2(): |
| 62 | + on_info("Test 2/7 (ffprobe)...") |
| 63 | + try: |
| 64 | + on_info(" Trying to call ffprobe...") |
| 65 | + from aeneas.ffprobewrapper import FFPROBEWrapper |
| 66 | + file_path = get_abs_path("aeneas/tools/res/audio.mp3") |
| 67 | + prober = FFPROBEWrapper() |
| 68 | + properties = prober.read_properties(file_path) |
| 69 | + on_info(" Trying to call ffprobe... succeeded.") |
| 70 | + return True |
| 71 | + except: |
| 72 | + on_error(" Unable to call ffprobe.") |
| 73 | + on_error(" Please make sure you have ffprobe installed correctly and that it is in your $PATH.") |
| 74 | + return False |
| 75 | + |
| 76 | +def step3(): |
| 77 | + on_info("Test 3/7 (ffmpeg)...") |
| 78 | + try: |
| 79 | + on_info(" Trying to call ffmpeg...") |
| 80 | + from aeneas.ffmpegwrapper import FFMPEGWrapper |
| 81 | + import aeneas.globalfunctions as gf |
| 82 | + input_file_path = get_abs_path("aeneas/tools/res/audio.mp3") |
| 83 | + handler, output_file_path = tempfile.mkstemp(suffix=".wav") |
| 84 | + converter = FFMPEGWrapper() |
| 85 | + result = converter.convert(input_file_path, output_file_path) |
| 86 | + gf.delete_file(handler, output_file_path) |
| 87 | + if result: |
| 88 | + on_info(" Trying to call ffmpeg... succeeded.") |
| 89 | + return True |
| 90 | + else: |
| 91 | + on_error(" Unable to call ffmpeg.") |
| 92 | + on_error(" Please make sure you have ffmpeg installed correctly and that it is in your $PATH.") |
| 93 | + except: |
| 94 | + on_error(" Unable to call ffmpeg.") |
| 95 | + on_error(" Please make sure you have ffmpeg installed correctly and that it is in your $PATH.") |
| 96 | + return False |
| 97 | + |
| 98 | +def step4(): |
| 99 | + on_info("Test 4/7 (espeak)...") |
| 100 | + try: |
| 101 | + on_info(" Trying to call espeak...") |
| 102 | + from aeneas.espeakwrapper import ESPEAKWrapper |
| 103 | + from aeneas.language import Language |
| 104 | + import aeneas.globalfunctions as gf |
| 105 | + text = u"From fairest creatures we desire increase," |
| 106 | + language = Language.EN |
| 107 | + handler, output_file_path = tempfile.mkstemp(suffix=".wav") |
| 108 | + espeak = ESPEAKWrapper() |
| 109 | + result = espeak.synthesize_single( |
| 110 | + text, |
| 111 | + language, |
| 112 | + output_file_path, |
| 113 | + force_pure_python=True |
| 114 | + ) |
| 115 | + gf.delete_file(handler, output_file_path) |
| 116 | + if result: |
| 117 | + on_info(" Trying to call espeak... succeeded.") |
| 118 | + return True |
| 119 | + else: |
| 120 | + on_error(" Unable to call espeak.") |
| 121 | + on_error(" Please make sure you have espeak installed correctly and that it is in your $PATH.") |
| 122 | + except: |
| 123 | + on_error(" Unable to call espeak.") |
| 124 | + on_error(" Please make sure you have espeak installed correctly and that it is in your $PATH.") |
| 125 | + return False |
| 126 | + |
| 127 | +def stepC1(): |
| 128 | + on_info("Test 5/7 (cdtw)...") |
| 129 | + try: |
| 130 | + import aeneas.cdtw |
| 131 | + on_info(" Python C Extension cdtw correctly loaded") |
| 132 | + return True |
| 133 | + except: |
| 134 | + on_warning(" Unable to load Python C Extension cdtw") |
| 135 | + on_warning(" You can still run aeneas, but it will much slower") |
| 136 | + on_warning(" Try running %s to compile the cdtw module" % SETUP_COMMAND) |
| 137 | + return False |
| 138 | + |
| 139 | +def stepC2(): |
| 140 | + on_info("Test 6/7 (cmfcc)...") |
| 141 | + try: |
| 142 | + import aeneas.cmfcc |
| 143 | + on_info(" Python C Extension cmfcc correctly loaded") |
| 144 | + return True |
| 145 | + except: |
| 146 | + on_warning(" Unable to load Python C Extension cmfcc") |
| 147 | + on_warning(" You can still run aeneas, but it will be a bit slower") |
| 148 | + on_warning(" Try running %s to compile the cmfcc module" % SETUP_COMMAND) |
| 149 | + return False |
| 150 | + |
| 151 | +def stepC3(): |
| 152 | + on_info("Test 7/7 (cew)...") |
| 153 | + if not ((os.name == "posix") and (os.uname()[0] == "Linux")): |
| 154 | + on_info(" Python C Extension cew is not available for your OS") |
| 155 | + on_info(" You can still run aeneas, but it will be a bit slower than Linux") |
| 156 | + return True |
| 157 | + try: |
| 158 | + import aeneas.cew |
| 159 | + on_info(" Python C Extension cew correctly loaded") |
| 160 | + return True |
| 161 | + except: |
| 162 | + on_warning(" Unable to load Python C Extension cew") |
| 163 | + on_warning(" You can still run aeneas, but it will be a bit slower") |
| 164 | + on_warning(" Try running %s to compile the cew module" % SETUP_COMMAND) |
| 165 | + return False |
| 166 | + |
| 167 | +def main(): |
| 168 | + if not step1(): |
| 169 | + return |
| 170 | + |
| 171 | + if not step2(): |
| 172 | + return |
| 173 | + |
| 174 | + if not step3(): |
| 175 | + return |
| 176 | + |
| 177 | + if not step4(): |
| 178 | + return |
| 179 | + |
| 180 | + has_cdtw = stepC1() |
| 181 | + has_cmfcc = stepC2() |
| 182 | + has_cew = stepC3() |
| 183 | + |
| 184 | + if has_cdtw and has_cmfcc and has_cew: |
| 185 | + on_info("Congratulations, all dependencies are met and core C extensions are available.") |
| 186 | + else: |
| 187 | + on_warning("All dependencies are met, but at least one core C extension has not been compiled.") |
| 188 | + on_warning("Try running %s to compile the C extensions." % SETUP_COMMAND) |
| 189 | + |
| 190 | + on_info("Enjoy running aeneas!") |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | +if __name__ == '__main__': |
| 195 | + main() |
| 196 | + |
| 197 | + |
| 198 | + |
0 commit comments