Spaces:
Running
Running
fix: 依旧编码问题
Browse files- src/gui_cloud.py +18 -3
src/gui_cloud.py
CHANGED
|
@@ -480,17 +480,32 @@ def process_make_voicebank(
|
|
| 480 |
os.makedirs(bank_dir, exist_ok=True)
|
| 481 |
|
| 482 |
# 复制音频文件到输入目录
|
|
|
|
| 483 |
progress(0.05, desc="复制音频文件...")
|
| 484 |
copied_count = 0
|
| 485 |
-
for src_path in file_paths:
|
| 486 |
# 检查源文件是否存在
|
| 487 |
if not os.path.exists(src_path):
|
| 488 |
log(f"⚠️ 文件不存在或已被清理: {src_path}")
|
| 489 |
continue
|
| 490 |
try:
|
| 491 |
-
|
| 492 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
copied_count += 1
|
|
|
|
| 494 |
except Exception as e:
|
| 495 |
log(f"⚠️ 复制文件失败 {os.path.basename(src_path)}: {e}")
|
| 496 |
|
|
|
|
| 480 |
os.makedirs(bank_dir, exist_ok=True)
|
| 481 |
|
| 482 |
# 复制音频文件到输入目录
|
| 483 |
+
# 注意:Gradio 上传的文件名可能包含中文和空格,需要规范化
|
| 484 |
progress(0.05, desc="复制音频文件...")
|
| 485 |
copied_count = 0
|
| 486 |
+
for idx, src_path in enumerate(file_paths):
|
| 487 |
# 检查源文件是否存在
|
| 488 |
if not os.path.exists(src_path):
|
| 489 |
log(f"⚠️ 文件不存在或已被清理: {src_path}")
|
| 490 |
continue
|
| 491 |
try:
|
| 492 |
+
# 获取原始文件名和扩展名
|
| 493 |
+
original_name = os.path.basename(src_path)
|
| 494 |
+
_, ext = os.path.splitext(original_name)
|
| 495 |
+
ext = ext.lower()
|
| 496 |
+
|
| 497 |
+
# 生成安全的文件名(避免中文和空格导致的问题)
|
| 498 |
+
safe_name = f"audio_{idx:04d}{ext}"
|
| 499 |
+
dst_path = os.path.join(input_dir, safe_name)
|
| 500 |
+
|
| 501 |
+
# 使用二进制模式复制,确保文件完整性
|
| 502 |
+
with open(src_path, 'rb') as fsrc:
|
| 503 |
+
content = fsrc.read()
|
| 504 |
+
with open(dst_path, 'wb') as fdst:
|
| 505 |
+
fdst.write(content)
|
| 506 |
+
|
| 507 |
copied_count += 1
|
| 508 |
+
log(f" {original_name} -> {safe_name}")
|
| 509 |
except Exception as e:
|
| 510 |
log(f"⚠️ 复制文件失败 {os.path.basename(src_path)}: {e}")
|
| 511 |
|