def versionInfo(): res = [] buildInfoFile = "/wikispeech/wikispeech_server/build_info.txt" if os.path.isfile(buildInfoFile): with open(buildInfoFile) as fp: lines = fp.readlines() fp.close() for l in lines: res.append(l.strip()) else: res.append("Application name: wikispeech") res.append("Build timestamp: n/a") res.append("Built by: user") try: tag = subprocess.check_output(["git","describe","--tags"]).decode("utf-8").strip() branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode("utf-8").strip() print(tag) print(branch) res.append( ("Release: %s on branch %s") % (tag, branch) ) except: log.warning("couldn't retrieve git release info: %s" % sys.exc_info()[1]) res.append("Release: unknown"); res.append("Started: " + startedAt) return res
def test(self): url = "%s/list" % self.base_url log.debug("LEXICON URL: %s" % url) #print("LEXICON URL: %s" % url) try: r = requests.get(url) response = r.text response_json = json.loads(response) #print(response_json) exists = False #print(response_json) for lex in response_json: if lex['name'] == self.lexicon_name: exists = True if not exists: msg = "Lexicon does not exist: %s" % (self.lexicon_name) log.error(msg) raise LexiconException(msg) except json.JSONDecodeError: msg = "Unable to create lexicon client for %s. Response was: %s" % ( self.lexicon_name, response) log.error(msg) raise LexiconException(msg) except Exception as e: msg = "Unable to create lexicon client for %s at url %s. Reason: %s" % ( self.lexicon_name, url, e) log.warning(msg) raise LexiconException(msg)
def test(self): url = "%s/list" % self.base_url log.debug("LEXICON URL: %s" % url) print("LEXICON URL: %s" % url) try: r = requests.get(url) response = r.text response_json = json.loads(response) print(response_json) exists = False print(response_json) for lex in response_json: if lex['name'] == self.lexicon_name: exists = True if not exists: msg = "Lexicon does not exist: %s" % (self.lexicon_name) log.error(msg) raise LexiconException(msg) except json.JSONDecodeError: msg = "Unable to create lexicon client for %s. Response was: %s" % (self.lexicon_name, response) log.error(msg) raise LexiconException(msg) except Exception as e: msg = "Unable to create lexicon client for %s at url %s. Reason: %s" % (self.lexicon_name, url, e) log.warning(msg) raise LexiconException(msg)
def __init__(self, voice_config): self.config = voice_config self.name = voice_config["name"] self.lang = voice_config["lang"] self.engine = voice_config["engine"] self.adapter = voice_config["adapter"] if "skip_test" in voice_config and voice_config["skip_test"] == True: pass else: try: if "directory" in voice_config: directory = voice_config["directory"] else: directory = "wikispeech_server" adapter = util.import_module(directory, self.config["adapter"]) adapter.testVoice(self.config) except Exception as e: msg = "Test failed for adapter %s. Reason: %s" % (self.adapter, e) log.warning(msg) raise if "mapper" in voice_config: try: self.mapper = Mapper(voice_config["mapper"]["from"], voice_config["mapper"]["to"]) except MapperException as e: raise VoiceException(e)
def loadJsonConfigurationFiles(): global textprocessor_configs, voice_configs textprocessor_configs = [] voice_configs = [] cf_dir = "wikispeech_server" if config.config.has_option("Voice config", "config_files_location"): cf_dir = config.config.get("Voice config", "config_files_location") #The testing config file should always be there #config_files = ["voice_config_for_testing.json"] #OR maybe it shouldn't?? config_files = [] if config.config.has_option("Voice config", "config_files"): #print(config.config.get("Voice config", "config_files")) cfs = config.config.get("Voice config", "config_files").split("\n") for cf in cfs: if cf not in config_files and cf != "": config_files.append(cf) for config_file in config_files: if os.path.isfile(config_file): path = config_file elif os.path.isfile("%s/%s" % (cf_dir, config_file)): path = "%s/%s" % (cf_dir, config_file) else: print("Config file %s or %s not found" % (config_file, "%s/%s" % (cf_dir, config_file))) sys.exit() with open(path) as json_file: log.info("Reading config file: %s" % path) json_like = json_file.read() json_str = remove_comments(json_like) #cf = json.load(json_file) cf = json.loads(json_str) if "textprocessor_configs" in cf: for tconf in cf["textprocessor_configs"]: #Is the tp name already in the list? addTp = True for tc in textprocessor_configs: if tc["name"] == tconf["name"]: log.warning("Textprocessor %s defined more than once: file %s" % (tconf["name"], path)) addTp = False if addTp: tconf["config_file"] = path textprocessor_configs.append(tconf) if "voice_configs" in cf: for vconf in cf["voice_configs"]: #Is the voice name already in the list? addVoice = True for vc in voice_configs: if vc["name"] == vconf["name"]: log.warning("Voice %s defined more than once: file %s" % (vconf["name"], path)) addVoice = False if addVoice: vconf["config_file"] = path voice_configs.append(vconf)
def loadVoice(voice_config): try: log.info("Loading voice %s" % (voice_config["name"])) v = Voice(voice_config) log.info("Done loading voice %s" % (voice_config["name"])) voices.append(v) except VoiceException as e: log.warning("Failed to load voice from %s. Reason:\n%s" % (voice_config,e)) raise
def loadTextprocessor(tp_config): try: log.info("Loading textprocessor %s" % (tp_config["name"])) tp = Textprocessor(tp_config) log.info("Done loading textprocessor %s" % (tp_config["name"])) textprocessors.append(tp) except TextprocessorException as e: log.warning("Failed to load textprocessor from %s. Reason:\n%s" % (tp_config,e)) raise
def lookup(self, string): if string.strip() == "": log.warning("LEXICON LOOKUP STRING IS EMPTY!") return {} encString = urllib.parse.quote(string) url = "%s/%s?lexicons=%s&words=%s" % (self.base_url, "lookup", self.lexicon_name, encString) r = requests.get(url) log.debug("LEXICON LOOKUP URL: %s" % r.url) response = r.text try: response_json = json.loads(response) log.debug(response_json) return response_json except: log.error("unable to lookup '%s' in %s. response was %s" % (string, self.lexicon_name, response)) raise LexiconException(response)
def loadVoice(voice_config): try: v = Voice(voice_config) voices.append(v) except VoiceException as e: log.warning("Failed to load voice from %s. Reason:\n%s" % (voice_config,e))
def loadTextprocessor(tp_config): try: tp = Textprocessor(tp_config) textprocessors.append(tp) except TextprocessorException as e: log.warning("Failed to load textprocessor from %s. Reason:\n%s" % (tp_config,e))