From 15b7779ab4d178a9c46ffae8502c7d595e1e6211 Mon Sep 17 00:00:00 2001 From: BKK <2715673327@QQ.COM> Date: Sun, 24 Nov 2024 12:04:19 +0800 Subject: [PATCH] fix --- app/core/subtitle_processor/spliter.py | 10 ++++------ app/core/thread/transcript_thread.py | 11 +++++++---- app/view/subtitle_style_interface.py | 8 +++++--- app/view/task_creation_interface.py | 13 +++++++------ ...227\273\345\244\247\345\255\227\351\243\216.txt" | 4 ---- 5 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 "resource/subtitle_style/\346\226\260\351\227\273\345\244\247\345\255\227\351\243\216.txt" diff --git a/app/core/subtitle_processor/spliter.py b/app/core/subtitle_processor/spliter.py index 69c40ab..f5f26d6 100644 --- a/app/core/subtitle_processor/spliter.py +++ b/app/core/subtitle_processor/spliter.py @@ -8,7 +8,7 @@ from ..bk_asr.ASRData import ASRData, from_srt, ASRDataSeg from ..utils.logger import setup_logger -logger = setup_logger("subtitle_spliter", level=logging.DEBUG) +logger = setup_logger("subtitle_spliter") SEGMENT_THRESHOLD = 500 # 每个分段的最大字数 FIXED_NUM_THREADS = 4 # 固定的线程数量 @@ -145,12 +145,12 @@ def merge_segments_based_on_sentences(asr_data: ASRData, sentences: List[str]) - new_segments.extend(split_segs) else: new_segments.append(merged_seg) - max_shift = 100 + max_shift = 30 asr_index = end_seg_index + 1 # 移动到下一个未处理的分段 else: logger.warning(f"无法匹配句子: {sentence}") - max_shift = 30 - asr_index += 1 + max_shift = 100 + asr_index = end_seg_index + 1 return ASRData(new_segments) @@ -243,7 +243,6 @@ def split_asr_data(asr_data: ASRData, num_segments: int) -> List[ASRData]: """ total_segs = len(asr_data.segments) total_word_count = count_words(asr_data.to_txt()) - print(f"总字数: {total_word_count}") words_per_segment = total_word_count // num_segments split_indices = [] @@ -349,7 +348,6 @@ def process_segment(asr_data_part): txt = asr_data_part.to_txt().replace("\n", "") sentences = split_by_llm(txt, model=model, use_cache=True) logger.info(f"分段的句子提取完成,共 {len(sentences)} 句") - print(f"sentences: {sentences}") return sentences diff --git a/app/core/thread/transcript_thread.py b/app/core/thread/transcript_thread.py index d0e1d30..9595352 100644 --- a/app/core/thread/transcript_thread.py +++ b/app/core/thread/transcript_thread.py @@ -99,10 +99,13 @@ def run(self): logger.info("字幕文件已保存到: %s", str(original_subtitle_path)) # 删除音频文件 和 封面 - audio_save_path.unlink() - thumbnail_path = Path(self.task.video_info.thumbnail_path) - if thumbnail_path.exists(): - thumbnail_path.unlink() + try: + audio_save_path.unlink() + thumbnail_path = Path(self.task.video_info.thumbnail_path) + if thumbnail_path.exists(): + thumbnail_path.unlink() + except Exception as e: + logger.error("删除音频文件或封面失败: %s", str(e)) self.progress.emit(100, self.tr("转录完成")) self.finished.emit(self.task) diff --git a/app/view/subtitle_style_interface.py b/app/view/subtitle_style_interface.py index 35f2531..865c206 100644 --- a/app/view/subtitle_style_interface.py +++ b/app/view/subtitle_style_interface.py @@ -315,6 +315,11 @@ def _initStyle(self): def __setValues(self): """设置初始值""" + # 设置字幕排布 + self.layoutCard.comboBox.setCurrentText(cfg.get(cfg.subtitle_layout)) + # 设置字幕样式 + self.styleNameComboBox.comboBox.setCurrentText(cfg.get(cfg.subtitle_style_name)) + # 获取系统字体,设置comboBox的选项 fontDatabase = QFontDatabase() fontFamilies = fontDatabase.families() @@ -339,9 +344,6 @@ def __setValues(self): self.loadStyle(style_files[0]) self.styleNameComboBox.comboBox.setCurrentText(style_files[0]) - # 设置字幕排布 - self.layoutCard.comboBox.setCurrentText(cfg.get(cfg.subtitle_layout)) - def connectSignals(self): """连接所有设置变更的信号到预览更新函数""" # 字幕排布 diff --git a/app/view/task_creation_interface.py b/app/view/task_creation_interface.py index f10f428..630ca2e 100644 --- a/app/view/task_creation_interface.py +++ b/app/view/task_creation_interface.py @@ -256,12 +256,13 @@ def setup_values(self): self.transcription_model_card.value() == TranscribeModelEnum.WHISPER.value or self.transcription_model_card.value() == TranscribeModelEnum.WHISPER_API.value ) - InfoBar.warning( - self.tr("警告,将使用自带小模型API"), - self.tr("为确保字幕修正的准确性,建议到设置中配置自己的API"), - duration=8000, - parent=self, - position=InfoBarPosition.BOTTOM_RIGHT + if cfg.api_base == "": + InfoBar.warning( + self.tr("警告"), + self.tr("为确保字幕修正的准确性,建议到设置中配置自己的API"), + duration=6000, + parent=self, + position=InfoBarPosition.BOTTOM_RIGHT ) def on_transcription_model_changed(self, value): diff --git "a/resource/subtitle_style/\346\226\260\351\227\273\345\244\247\345\255\227\351\243\216.txt" "b/resource/subtitle_style/\346\226\260\351\227\273\345\244\247\345\255\227\351\243\216.txt" deleted file mode 100644 index c6ea422..0000000 --- "a/resource/subtitle_style/\346\226\260\351\227\273\345\244\247\345\255\227\351\243\216.txt" +++ /dev/null @@ -1,4 +0,0 @@ -[V4+ Styles] -Format: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding -Style: Default,微软雅黑,60,&H00e6e8f1,&H000000FF,&H00060606,&H00000000,-1,0,0,0,100,100,3.0,0,1,2.2,0,2,10,10,10,1 -Style: Secondary,微软雅黑,36,&H00ffffff,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0.0,0,1,2.0,0,2,10,10,10,1 \ No newline at end of file