Skip to content

Commit a08c51c

Browse files
committed
fix(ui): 优化文件名生成逻辑
- 移除文件名中的特殊字符,仅保留汉字、字母和下划线 - 使用正则表达式替换掉换行符、逗号、引号等不适合出现在文件名中的字符
1 parent 6ba01d7 commit a08c51c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ui/main_window.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def _on_conversion_finished(self, result):
7979

8080
# 生成文件名 (使用前20个字符作为文件名)
8181
text = self.conversion_panel.text_input.toPlainText()[:20]
82-
filename = f"{text}_{int(time.time())}.{self.conversion_panel.format_combo.currentText()}"
82+
# 文件名去掉换行符,逗号,引号,感叹号,问号等等特殊字符,仅保留汉字和字母及下划线
83+
filename = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9_]', '', text)
84+
filename = f"{filename}_{int(time.time())}.{self.conversion_panel.format_combo.currentText()}"
8385

8486
# 保存音频文件
8587
filepath = self.core.audio_mgr.save_audio(result, filename, output_dir)

0 commit comments

Comments
 (0)