Spaces:
Sleeping
Sleeping
fix: UTAU 导出编码问题
Browse files
src/export_plugins/utau_oto_export.py
CHANGED
|
@@ -873,6 +873,22 @@ class UTAUOtoExportPlugin(ExportPlugin):
|
|
| 873 |
output_path: str,
|
| 874 |
encoding: str
|
| 875 |
):
|
| 876 |
-
"""写入 character.txt 文件,用于 UTAU 识别音源名称
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 877 |
with open(output_path, 'w', encoding=encoding) as f:
|
| 878 |
-
f.write(f"name={
|
|
|
|
| 873 |
output_path: str,
|
| 874 |
encoding: str
|
| 875 |
):
|
| 876 |
+
"""写入 character.txt 文件,用于 UTAU 识别音源名称
|
| 877 |
+
|
| 878 |
+
注意:当音源名称包含无法用指定编码表示的字符时,
|
| 879 |
+
自动将名称转换为拼音/罗马音。
|
| 880 |
+
"""
|
| 881 |
+
name_to_write = source_name
|
| 882 |
+
|
| 883 |
+
# 检测是否能用指定编码
|
| 884 |
+
try:
|
| 885 |
+
source_name.encode(encoding)
|
| 886 |
+
except UnicodeEncodeError:
|
| 887 |
+
# 无法编码,转换为拼音
|
| 888 |
+
from pypinyin import lazy_pinyin
|
| 889 |
+
pinyin_name = ''.join(lazy_pinyin(source_name))
|
| 890 |
+
logger.warning(f"音源名称 '{source_name}' 无法用 {encoding} 编码,已转换为拼音: {pinyin_name}")
|
| 891 |
+
name_to_write = pinyin_name
|
| 892 |
+
|
| 893 |
with open(output_path, 'w', encoding=encoding) as f:
|
| 894 |
+
f.write(f"name={name_to_write}")
|