mirror of https://github.com/coqui-ai/TTS.git
33 lines
974 B
Python
33 lines
974 B
Python
import re
|
|
import json
|
|
|
|
class AttrDict(dict):
|
|
def __init__(self, *args, **kwargs):
|
|
super(AttrDict, self).__init__(*args, **kwargs)
|
|
self.__dict__ = self
|
|
|
|
|
|
def load_config(config_path):
|
|
config = AttrDict()
|
|
with open(config_path, "r") as f:
|
|
input_str = f.read()
|
|
input_str = re.sub(r'\\\n', '', input_str)
|
|
input_str = re.sub(r'//.*\n', '\n', input_str)
|
|
data = json.loads(input_str)
|
|
config.update(data)
|
|
return config
|
|
|
|
|
|
def copy_config_file(config_file, out_path, new_fields):
|
|
config_lines = open(config_file, "r").readlines()
|
|
# add extra information fields
|
|
for key, value in new_fields.items():
|
|
if isinstance(value, str):
|
|
new_line = '"{}":"{}",\n'.format(key, value)
|
|
else:
|
|
new_line = '"{}":{},\n'.format(key, value)
|
|
config_lines.insert(1, new_line)
|
|
config_out_file = open(out_path, "w")
|
|
config_out_file.writelines(config_lines)
|
|
config_out_file.close()
|