Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
WEIFENG2333 committed Nov 24, 2024
1 parent 2545c6b commit 15b7779
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
10 changes: 4 additions & 6 deletions app/core/subtitle_processor/spliter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 # 固定的线程数量
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 = []

Expand Down Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions app/core/thread/transcript_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions app/view/subtitle_style_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
"""连接所有设置变更的信号到预览更新函数"""
# 字幕排布
Expand Down
13 changes: 7 additions & 6 deletions app/view/task_creation_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 0 additions & 4 deletions resource/subtitle_style/新闻大字风.txt

This file was deleted.

0 comments on commit 15b7779

Please sign in to comment.