|
|
import os |
|
|
import yaml |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def convert_yaml_to_esd_list(): |
|
|
""" |
|
|
esd.yaml を読み込み、esd.list 形式に変換して出力します。 |
|
|
""" |
|
|
try: |
|
|
|
|
|
base_dir = os.path.dirname(os.path.abspath(__file__)) |
|
|
input_yaml_path = os.path.join(base_dir, "Inputs", "esd.yaml") |
|
|
output_dir = os.path.join(base_dir, "Outputs") |
|
|
output_list_path = os.path.join(output_dir, "esd.list") |
|
|
|
|
|
|
|
|
os.makedirs(output_dir, exist_ok=True) |
|
|
|
|
|
|
|
|
print(f"'{input_yaml_path}' を読み込んでいます...") |
|
|
with open(input_yaml_path, 'r', encoding='utf-8') as f: |
|
|
data = yaml.safe_load(f) |
|
|
print("読み込みが完了しました。") |
|
|
|
|
|
output_lines = [] |
|
|
speaker = "Tsukuyomi-chan" |
|
|
language = "JP" |
|
|
|
|
|
|
|
|
print("データを esd.list 形式に変換しています...") |
|
|
for key, value in data.items(): |
|
|
if isinstance(value, dict) and 'text_level2' in value: |
|
|
filename = f"{key}.wav" |
|
|
text = value['text_level2'] |
|
|
|
|
|
line = f"{filename}|{speaker}|{language}|{text}" |
|
|
output_lines.append(line) |
|
|
|
|
|
|
|
|
print(f"'{output_list_path}' に書き込んでいます...") |
|
|
with open(output_list_path, 'w', encoding='utf-8') as f: |
|
|
f.write('\n'.join(output_lines)) |
|
|
|
|
|
print("変換が正常に完了しました。") |
|
|
print(f"出力ファイル: {output_list_path}") |
|
|
|
|
|
except FileNotFoundError: |
|
|
print(f"エラー: 入力ファイルが見つかりません。パスを確認してください: {input_yaml_path}") |
|
|
except Exception as e: |
|
|
print(f"エラーが発生しました: {e}") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
convert_yaml_to_esd_list() |
|
|
|